score:0

Accepted answer

When using the useState hook without an explicit generic, TypeScript will try to infer the type from the initial passed value.

Since your initial value includes an empty array (for images), TypeScript is unable to determine the type of the values that will be in that array and so assigns it the type never.

To fix this, explicitly specify the type of your state when you initialize it:

const [colorsAndImages, setColorsAndImages] = useState<{images: File[], colors: string}[]>([{ images: [], colors: '' }])

Related Query

More Query from same tag