Filters values set to a directly so that the value only changes when the filter is passed. Some overloads allow for a guard function which will change the type of the signal's output value.
const nonNegative = filterSignal<number>(0, x => x >= 0);nonNegative.set(-1);console.log(nonNegative()); // [LOG]: 0 Copy
const nonNegative = filterSignal<number>(0, x => x >= 0);nonNegative.set(-1);console.log(nonNegative()); // [LOG]: 0
The input value of the signal
The output type of the signal or the value of the input and output if no guard function is used.
The initial value of the signal
A function that filters values. Can be a guard function.
Options for the signal.
A writable signal whose values are only updated when set.
Optional
Filters values set to a directly so that the value only changes when the filter is passed. Some overloads allow for a guard function which will change the type of the signal's output value.
Example
Type Param: T
The input value of the signal
Type Param: O
The output type of the signal or the value of the input and output if no guard function is used.
Param: initialValue
The initial value of the signal
Param: filterFn
A function that filters values. Can be a guard function.
Param: options
Options for the signal.
Returns
A writable signal whose values are only updated when set.