--- title: TypeScript description: How to use Jotai with TypeScript nav: 3.01 --- ## Version requirement Jotai uses TypeScript 3.8+ syntax. Upgrade your TypeScript version if you're on 3.7.5 or lower. Jotai relies heavily on type inferences and requires `strictNullChecks` to be enabled. Consider adding `"strict": true` in your tsconfig.json. [#550](https://github.com/pmndrs/jotai/issues/550) [#802](https://github.com/pmndrs/jotai/issues/802) [#838](https://github.com/pmndrs/jotai/issues/838) ## Notes ### Primitive atoms are basically type inferred ```js const numAtom = atom(0) // primitive number atom const strAtom = atom('') // primitive string atom ``` ### Primitive atoms can be explicitly typed ```ts const numAtom = atom(0) const numAtom = atom(0) const arrAtom = atom([]) ``` ### Derived atoms are also type inferred and explicitly typed ```ts const asyncStrAtom = atom(async () => "foo") const writeOnlyAtom = atom(null, (_get, set, str: string) => set(fooAtom, str) const readWriteAtom = atom( get => get(strAtom), (_get, set, num) => set(strAtom, String(num)) ) ``` ### useAtom is typed based on atom types ```js const [num, setNum] = useAtom(primitiveNumAtom) const [num] = useAtom(readOnlyNumAtom) const [, setNum] = useAtom(writeOnlyNumAtom) ```