Typescript 3.2 新特性
1. bigint 类型
Typescript 3.2 引入了 bigint
类型,它可以表示任意精度的整数。
1 | let x: bigint = 100n; |
不能将 bigint
类型的值赋值给 number
类型的变量,也不能将 number
类型的值赋值给 bigint
类型的变量。
1 | let x: bigint = 100n; |
2. ts config 继承
Typescript 3.2 引入了 extends
选项,可以继承其他的 tsconfig.json
文件。
通过 compilerOptions
选项可以覆盖继承的 tsconfig.json
文件中的配置。
1 | { |
3. const
断言
Typescript 3.2 引入了 const
断言,可以将一个表达式断言为 const
类型。
不同于 as const
,const
断言不会将对象的属性变为 readonly
。
1 | let x = { a: 1 } as const; |
4. Omit 类型
Typescript 3.5 引入了 Omit
类型,它可以从一个类型中排除指定的属性。
1 | type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; |
评论
评论插件加载失败
正在加载评论插件