React TypeScript: Type 'string[]' is not assignable to type 'never[]'

Viewed 4457

When I save an array to a state and then read it back again I get the error Type 'string[]' is not assignable to type 'never[]' what is this all about?

I made a code sandbox here: https://codesandbox.io/s/affectionate-pasteur-kj5h0 where the code runs but shows the error in red underlines

1 Answers

If you strongly type the generic param for useState you're all good

const [state, setState] = useState<{ array1: string[] }>({ array1: [] });
Related