【发布时间】:2023-02-22 10:08:32
【问题描述】:
由于 TS 不允许以下语法:
anObject['aKey'] = 'aValue';
我正在创建以下接口并从中继承所有对象:
interface KeyIndexable {
[key: string]: any;
}
interface ObjectA extends KeyIndexable {
a: string;
b: number;
}
但是现在当我尝试创建一个通用函数变量时,如下所示:
let x: <T extends KeyIndexable>(t: T) => void;
x = (a: ObjectA) => console.log('x');
我收到一条错误消息 Type KeyIndexable is missing the following properties from type ObjectA。
那么在这种情况下我该如何解决呢?
【问题讨论】:
标签: typescript