You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

21 lines
537 B

// 索引签名类型
// 使用场景:无法确定对象中有哪些属性(或者对象中出现任意多个属性) 例:用户输入的内容
interface AnyObject {
// 字符串的键都可以出现在 AnyObject 对象中
[key: string] : number // key 表示一个占位符(可以更改名字),number 表示属性的值的类型
}
let obj: AnyObject = {
a: 1,
abc: 123,
}
// 在数组中使用
interface MyArray<Type> {
[index: number]: Type
}
let arr1 : MyArray<number> = [1, 3, 5]
arr1[0]