考虑以下使用:和in定义索引签名的示例:
interface Colon {
[key : string]: number;
}
interface ColonOpt {
[key : string]?: number; // does not compile
}
interface In {
[key in string]: number; // does not compile
}
interface InNested {
a: {
[key in string]: number;
};
}
interface InNestedOpt {
a: {
[key in string]?: number;
};
}
Run Code Online (Sandbox Code Playgroud)
我有点困惑为什么有些可以编译而有些不能。in在索引签名中使用vs有什么区别:?
| 归档时间: |
|
| 查看次数: |
437 次 |
| 最近记录: |