我将此接口定义为我的状态:
interface State {
id: string;
name: string;
description: string;
dimensionID: string;
file: File | null;
operator: string;
isFormValid: boolean;
filename: string;
};
Run Code Online (Sandbox Code Playgroud)
我有一个简单的更改处理程序:
update = (event: React.FormEvent<HTMLInputElement>): void => {
const { name, value } = event.currentTarget;
this.setState({ [name]: value });
};
Run Code Online (Sandbox Code Playgroud)
然而,这个错误被抛出:
Error:(109, 19) TS2345: Argument of type '{ [x: string]: string; }' is not assignable to parameter of type 'State | Pick<State, "id" | "name" | "description" | "dimensionID" | "file" | "operator" | "isFormValid" | "filename"> …Run Code Online (Sandbox Code Playgroud)