core / type

DerivedValueGetterWithSignals

A function that computes a derived signal's value.

Source: src/_core/derive.ts

A function that computes a derived signal's value.

This function receives the previous computed value and should access .value on signals to establish dependencies. The function is called whenever any tracked dependency changes.

Signature

export type DerivedValueGetterWithSignals<T> = (oldValue: T | undefined) => T;

Type Parameters

  • The type of value to return

Parameters

  • oldValue: The previous computed value (undefined on first run)

Returns

The new computed value

Remarks

  • Always access signals via .value to establish dependencies
  • If a signal is accessed conditionally and the condition is false on first run, it won't be tracked
  • The previous value is the previous RETURN value, not the previous dependency values

Examples

const count = signal(5);
const doubled = derive((prev) => {
  const current = count.value;
  return current * 2;
});