类型标注

可用类型标注

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中:

  1. // 类装饰器
  2. declare type ClassDecorator =
  3. <TFunction extends Function>(target: TFunction) => TFunction | void;
  4. // 属性装饰器
  5. declare type PropertyDecorator =
  6. (target: Object, propertyKey: string | symbol) => void;
  7. // 函数装饰器
  8. declare type MethodDecorator =
  9. <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>)
  10. => TypedPropertyDescriptor<T> | void;
  11. // 参数装饰器
  12. declare type ParameterDecorator =
  13. (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;

装饰器使用示例https://gitee.com/yulangz/typescript-decorator