Replies: 2 comments 5 replies
-
|
Why don't you just use an effect instead of wrapping setLocalSignal? |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
Fortunately we can use const setItem = <T extends Value>(newValue?: Parameters<Setter<T>>[0]) => {
const res = setLocalItem<T>(newValue);
// Do stuff...
return res;
};On a separate note, it may be worth adding a export type SetterParameter<T, U extends T> =
| (U extends Function ? never : U)
| undefined extends T
? (prev?: T) => U
: (prev: T) => U;
export type Setter<T> = undefined extends T
? <U extends T>(v?: SetterParameter<T, U>) => U
: <U extends T>(v: SetterParameter<T, U>) => U; |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to create a (generic) custom signal, but I'm failing to make typescript happy:
Making it
anyis obviously not a great solution. I already tried overloading thesetItemfunction (because ifValueisundefinednewValueis optional) and narrowingnewValuetoValue | ((prev?: Value) => Value | undefined)(or similar). Both without success.I used the
Setter<T>interface to stay close to the normal way of using signals. That way it feels just like using a normal signal.What do I need to do to create a custom signal?
Beta Was this translation helpful? Give feedback.
All reactions