更新时间:2023-11-12 20:24:46
您需要告诉Typescript您的对象将具有IAddPlayerFormState的一个或多个属性,但不一定具有所有属性.您可以这样做:
You need to tell Typescript that your object will have one or more property from IAddPlayerFormState, but not necessarily all properties. You can do it like this:
public onChange(event: { target: { name: any; value: any; }; }) {
const newState = { [name]: value } as Pick<IAddPlayerFormState, keyof IAddPlayerFormState>;
this.setState(newState);
console.log("On Change!");
}