Reputation: 11267
I have the following:
interface FormValues {
max: number
}
Then, I do:
let [formValues, setFormValues] = useState({max: 5})
When I do console.log(formValues.max)
I get a typescript error. How do I tell the destructuring call that formValues
is of type FormValues
and that setFormValues
is a function?
This is not a duplicate of this:
Destructuring assignment in Typescript
or fo this:
Destructuring assignment via TypeScript in React
Neither of those answer the question
Upvotes: 0
Views: 74
Reputation: 2836
you can set the type of the state
export interface IValueType { max: number }
let [formValues, setFormValues] = useState<IValueType>({max: 5})
Upvotes: 1