假设我想在 Typescript 中定义这个方法:
setResult(guId: string,fieldname: string, data:Array<UsedTsoClusterKey>) {
let octdctruns: OctDctRun[] = [...this.octDctRuns];
const index = octdctruns.findIndex((o) => o.guid === guId);
octdctruns[index][fieldname] = data;
this.octDctRuns = octdctruns;
}
UsedTsoClusterKey 和 OctDctRun 看起来像这样:
export interface UsedTsoClusterKey {
runGUID: string;
tsoClusterKeyID: string;
tsoClusterKeyVersion: string;
validFrom: DateString;
validUntil: DateString;
}
export interface OctDctRun {
guid: string;
moduleType: string;
runTime: DateString;
calcIntervalFrom: DateString;
calcIntervalUntil: DateString;
triggerType: string;
triggerID: string;
usedTSOClusterKeys: UsedTsoClusterKey[];
}
但是我收到octdctruns[index][fieldname] = data行的错误:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'OctDctRun'.
No index signature with a parameter of type 'string' was found on type 'OctDctRun'
我不明白这里的问题。请帮忙!