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: '' }])
Source: stackoverflow.com
Related Query
- React Typescript - Argument of type is not assignable to parameter of type
- react usestate hooks error: argument of type 'yyy' is not assignable to parameter of type 'setstateaction<xx>'
- React with Typescript: Argument of type 'never[]' is not assignable to parameter of type 'StateProperties | (() => StateProperties)'
- React TypeScript: Argument is not assignable to parameter of type 'never'
- React Typescript: Argument of type '{ [x: number]: any; }' is not assignable to parameter of type
- React js Typescript Argument of type 'string' is not assignable to parameter of type 'SetStateAction<number>'
- React onclick Argument of type 'EventTarget' is not assignable to parameter of type 'Node'
- TypeScript w/ React - Argument of type 'string' is not assignable to parameter of type 'keyof T'
- Using state and includes in React gives Argument of type 'number' is not assignable to parameter of type 'never' error
- React and Typescript: Argument of type is not assignable to parameter of type 'EventListenerOrEventListenerObject'
- Argument of type '(props: ITableProps) => JSX.Element' is not assignable to parameter of type ... - React HOC
- Typescript React type argument of type not assignable to parameter of type
- Argument of type is not assignable to parameter of type 'SetStateAction<never[]>'. in React
- React Typescript: Argument of type is not assignable to parameter of type
- Typescript error on React Component: Argument of type 'Element' is not assignable to parameter of type
- TS and React State - Argument of type 'RangeModifier' is not assignable to parameter of type
- Argument of type 'File' is not assignable to parameter of type 'never'. React with TypeScript
- How to fix React TypeScript error: Argument of type '""' is not assignable to parameter of type 'SetStateAction<undefined>'
- How to fix the Argument of type 'Date[]' is not assignable to parameter of type '(prevState: undefined) in react
- Argument of type 'HTMLElement | null' is not assignable to parameter of type 'Element'. Type 'null' is not assignable to type 'Element'.ts(2345)
- Argument of type 'unknown' is not assignable to parameter of type '{}'
- Argument of type 'Element' is not assignable to parameter of type 'ReactElement<any>
- getting error : Argument of type '() => () => boolean' is not assignable to parameter of type 'EffectCallback'
- Typescript React/Redux : Argument of type 'typeof MyClass' is not assignable to parameter of type 'ComponentType<...'
- Argument of type '"MY_EVENTS_LOAD"' is not assignable to parameter of type 'TakeableChannel<unknown>' in yeild takeLatest
- Argument of type 'string' is not assignable to parameter of type '`${string}` | `${string}.${string}` | `${string}.${number}`'
- Argument of type '(dispatch: Dispatch) => void' is not assignable to parameter of type 'AnyAction'
- Argument of type partial is not assignable to parameter of type
- Argument of type 'Date | null' is not assignable to parameter of type 'SetStateAction<Date>'
- Argument of type 'number' is not assignable to parameter of type 'never' in array.includes()
More Query from same tag
- How do you import a javascript package from a cdn/script tag in React?
- Component Child is not re-rendered although state updated
- Fluent UI Web: How to change border radius of TextField?
- Can I move getInitialProps code to componentDidMount?
- ReactJS: STOMP subscription to multiple topics
- Module not found: Can't resolve './serviceWorker' in ../MyApp\src'
- increment and decrement not working properly
- Material-ui vertical divider in a button
- How come I can't navigate to the next page?
- Difference between useRef and normal variable
- how can export material-ui table to CSV?
- Redirect to last browser history location in React
- Child Components not being updated after updating context React
- React Js / using setTimout on jsx with state
- ./components/Avatar.tsx Error: Cannot find module '@babel/preset-stage-0'
- Why create-react-app changed App.js component to function based component?
- Can't fill my state in componentDidMound function
- react-bootstrap-table-next dependency tree issue
- Is there any way to return a plaintext response with React, containing no HTML at all?
- React styles prop returns [object object] for an array?
- reduxForm function of library redux-form v 7.0 not working with class component
- Change start of the week to Monday
- How to update or add to immutable.js List
- How to decode a url in JavaScript or NextJS?
- Managing Multiple Pages for React Application
- How to properly type React context provider
- Cannot make an "Errors" Object in a React Login Form Component's state function properly
- React router redirects me to /[object%20Object] instead of /login
- Module not found: Can't resolve '@material-ui/core/Avatar' in 'D:\own_files\ReactTutorial\react-app\src'
- Upload and read a file in react