Tiffany-yuan

Results 2 comments of Tiffany-yuan

TypeScript提供了很多数据类型,通过类型对变量进行限制,称之为类型注解,使用类型注解后,就不能够随意变更变量的类型。 我们可以使用类型别名或者接口来表示一个可被调用的类型注解: ```ts interface ReturnString { (): string; } ``` 它可以表示一个返回值为 `string` 的函数: ```ts declare const foo: ReturnString; const bar = foo(); // bar 被推断为一个字符串。 ```

使用索引类型,编译器就能够检查使用了动态属性名的代码 ```ts let person = { name: 'musion', age: 35 } function getValues(person: any, keys: string[]) { return keys.map(key => person[key]) } console.log(getValues(person, ['name', age])) // ['musion', 35] console.log(getValues(person, ['gender']))...