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
-
I'm trying to create a (generic) custom signal, but I'm failing to make typescript happy:
Making it
any
is obviously not a great solution. I already tried overloading thesetItem
function (because ifValue
isundefined
newValue
is optional) and narrowingnewValue
toValue | ((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