-
-
Notifications
You must be signed in to change notification settings - Fork 570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Atom state setter is of type never when initial value is null or undefined #838
Comments
I assume you are in the non-strict mode. (which isn't supported... unfortunately.) See this for workaround: #802 (comment) |
Ah yes, although not ideal enabling |
Yeah, it would be nice if it can be supported without too much hustle. We have tried it in #550, but anyone can try if they want to be challenged. Closing this, but this has been reported three times, so it's worth considering to add a note in docs. |
Maybe, leave it open for a while. |
Came here cause I just spent 30min being very confused as to how to set the values of atoms, thinking I was doing it wrong. Either way, I would love a note added to the docs about this problem. |
okay, let me work on adding a tiny note. |
const [count, setCount] = atom(null as number) This works for me with strict: false |
Cool. Do you mean |
The line I posted is the exact line I tried in my editor. I'm not a TS expert by an means. I can do this with strict:false
and
It appears both lines are equivalent. |
hey guys you should try this
import { SetStateAction, useAtom } from 'jotai';
const useTypeAtom = < T>(init: PrimitiveAtom< T>) => { |
When initializing an atom with
null
orundefined
the returned setter has a type ofnever
, which makes typescript unhappy whenever I try to invoke it to update the state.I'd be happy to look into it if needed.
The text was updated successfully, but these errors were encountered: