We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
You can continue the conversation there. Go to discussion →
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
I have this code and when i mouse hover to immerSetup.screen in vscode it shows any
immerSetup.screen
How do I make it typesafe ?
type Setup = { screen: string; }; const defaultSetup = { screen: "step1", }; // Original atom. const setupImmerAtom = atomWithImmer<Setup>(defaultSetup); const setScreen = (screen: Screen) => { const [setupAtom, setAtomSetup] = useAtom(setupImmerAtom); setAtomSetup((immerSetup) => { immerSetup.screen = screen; return immerSetup; }); };
On debugging further, I found out this
// actual type definition /node_modules/jotai-immer/dist/atomWithImmer.d.ts export declare function atomWithImmer<Value>(initialValue: Value): WritableAtom<Value, [Value | ((draft: Draft<Value>) => void)], void>; // resolving as this atomWithImmer<Setup>(initialValue: Setup): WritableAtom<Setup, [Setup | ((draft: Draft<Value>) => void)], void> // IT should resolve as this `Draft<Value>` to `Draft<Setup>` atomWithImmer<Setup>(initialValue: Setup): WritableAtom<Setup, [Setup | ((draft: Draft<Setup>) => void)], void>
By setting the generic type explicitly in atomWithImmer<Setup>, TypeScript should correctly infer Draft<Setup> instead of Draft<Value>.
atomWithImmer<Setup>
Draft<Setup>
Draft<Value>
No need just a typescript hint error
Please do not ask questions in issues.
Please include a minimal reproduction.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Summary
I have this code and when i mouse hover to
immerSetup.screen
in vscode it shows anyHow do I make it typesafe ?
On debugging further, I found out this
By setting the generic type explicitly in
atomWithImmer<Setup>
, TypeScript should correctly inferDraft<Setup>
instead ofDraft<Value>
.Link to reproduction
No need just a typescript hint error
Check List
Please do not ask questions in issues.
Please include a minimal reproduction.
The text was updated successfully, but these errors were encountered: