index 属性用来声明一个Object拥有的属性对应的类型。因为obj.property 类似 obj['property']
interface ErrorContainer {
[prop: string ]:string; // prop is not boolean type
}
const error : ErrorContainer = {
email:'this is a error',
1:'it is good' // number can convert to string
}
console.log(error["1"])
编译后的js
const error = {
email: 'this is a error',
1: 'it is good' // number can convert to string
};
console.log(error["1"]);
网友评论