In this react app there is a form with a few input fields. These fields all use this.handleChange with the onChange attribute.
private handleChange = (event: React.FormEvent<HTMLInputElement>) => {
let target = event.target as HTMLInputElement;
this.setState({
[target.name]: target.value
});
};
The typescript error I get is:
ERROR in [at-loader] ./src/components/FormSubmitHighScore.tsx:43:23
TS2345: Argument of type '{ [x: string]: string; }' is not assignable to parameter of type 'Pick<State, "first_name" | "last_name" | "email_address" | "school_name" | "region" | "submitted">'.
Property 'first_name' is missing in type '{ [x: string]: string; }'.
So by setting the state name field dynamically (based on what input is being used) this Typescript error gets triggered (but it does work in the browser).
How would I specify a correct type in this context?