我接口道:
export interface IView {
"Name": string,
"Type": number,
"IsOnlyCurrentWindow": boolean,
"IsDefault": boolean,
"IsShared": boolean,
"Id": string
}
对象属性和方法...
public currentSelectedView: IView | null = null;
public setCurrentView (view: IView) {
this.currentSelectedView = view;
}
public changeCurrentViewData(changeProperty: keyof IView, value: boolean | string) {
this.currentSelectedView[changeProperty] = value; // the TS error was occured
}
错误说明
请帮我正确键入
我已经尝试生成另一个类型(keyof IView on string),但再次出现错误
1条答案
按热度按时间6kkfgxo01#
您需要使用泛型来使参数类型与值类型匹配: