类型标注
可用类型标注
| string | 文本 |
|---|---|
| boolean | 布尔值 |
| number | 数值 |
| symbol | 通过Symbol构造函数创造的唯一值 |
| any | 任意类型,对应原生javascript对象 |
| unknown | 未知类型,使用前必须通过is语法进行转化 |
| never | 无法访问的代码(死循环函数的返回值等) |
| void | 无(返回) |
关于is语法,可以参见https://gitee.com/yulangz/typescript-helloworld/blob/master/hello.ts
装饰器
TypeScript中有几种装饰器的类型签名,在lib.es5.d.ts中:
// 类装饰器declare type ClassDecorator =<TFunction extends Function>(target: TFunction) => TFunction | void;// 属性装饰器declare type PropertyDecorator =(target: Object, propertyKey: string | symbol) => void;// 函数装饰器declare type MethodDecorator =<T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>)=> TypedPropertyDescriptor<T> | void;// 参数装饰器declare type ParameterDecorator =(target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
