You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I saw that Recoil recently gained support for using atoms as family parameters, but actually using them in TypeScript seems challenging unless the atoms are of the same type:
RecoilState<A | B> works for the selector definition, but the selector may not accept one of the atoms as a parameter
RecoilState<A> | RecoilState<B> produces a selector that accepts the expected params, but calls to set etc in the selector definition results in Types of property '__cTag' are incompatible.
My fix is to apply generics to the selector:
constnameSelector=selectorFamily<string,RecoilState<A|B>>({get: atom=>({ get })=>get(atom).name})as<TextendsA|B>(param: RecoilState<T>): RecoilState<string>
But I'm hoping there's something that can be tweaked in the library's TS typedefs to better support RecoilState unions.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I saw that Recoil recently gained support for using atoms as family parameters, but actually using them in TypeScript seems challenging unless the atoms are of the same type:
filling in this
SOMETHING
is the sticking point.RecoilState<A | B>
works for the selector definition, but the selector may not accept one of the atoms as a parameterRecoilState<A> | RecoilState<B>
produces a selector that accepts the expected params, but calls toset
etc in the selector definition results inTypes of property '__cTag' are incompatible.
My fix is to apply generics to the selector:
But I'm hoping there's something that can be tweaked in the library's TS typedefs to better support
RecoilState
unions.Beta Was this translation helpful? Give feedback.
All reactions