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

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.