Skip to content

Atom state setter is of type never when initial value is null or undefined #838

@nicmeriano

Description

@nicmeriano

When initializing an atom with null or undefined the returned setter has a type of never, which makes typescript unhappy whenever I try to invoke it to update the state.

// Works as expected - setCount: (update?: SetStateAction<number>) => void
const [count, setCount] = atom(0)

// Doesn't work as expected - setCount: never
const [count, setCount] = atom<number | null>(null);

I'd be happy to look into it if needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationhelp wantedPlease someone help on this

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions