pmndrs / jotai

👻 Primitive and flexible state management for React
https://jotai.org
MIT License
18.61k stars 607 forks source link

[TypeScript] Add `undefined` to Atom definition #2666

Closed rtritto closed 3 months ago

rtritto commented 3 months ago

Actual

With

const myAtom = atom<string>()

in VSCode I get

Expected 1 arguments, but got 0.ts(2554)
atom.d.ts(38, 37): An argument for 'read' was not provided

Instead, as workaround with

const myAtom = atom<string | undefined>()

in ESLint I get

error  Do not use useless `undefined`  unicorn/no-useless-undefined

Expected

No Error in VSCode with

const myAtom = atom<string>()

because Atom definition should already use undefined as default value

Related example (React)

const [myState, setMyState] = useState<string>()