我有一个基本界面:
interface Basic {
[key: string]: {
data: string;
};
}
扩展它的另一个接口:
interface Another extends Basic {
'onekey': OneKeyData;
'secondkey': SeconKeyData;
}
我的问题是当使用泛型T extends keyof Another
时,由于基本接口,它允许任何字符串键。OneKeyData 和 SecondKeyData 它们都包含data
Basic 中的属性。extends Basic
如果它没有在其他地方使用,我会删除:
interface Options<TKey extends keyof Another> {
field: Another[TKey]['data'];
}
在这种情况下,最好的解决方案是什么?是否有可能keyof
只获得Another
接口?