Typescript 3.8 新特性
Max Zhang Lv4

1. #private

Typescript 3.8 引入了 #private 修饰符,可以在类中声明私有属性。

1
2
3
4
5
6
7
8
class Foo {
#bar = 10;
constructor() {
console.log(this.#bar); // OK
}
}

console.log(new Foo().#bar); // Error

2. top level await

Typescript 3.8 引入了 top level await,可以在模块的顶层使用 await

1
2
3
4
5
6
7
8
9
10
11
// index.ts
const x = await fetch("https://example.com");
console.log(x);

// tsconfig.json
{
"compilerOptions": {
"module": "esnext",
"target": "es2017"
}
}

3. type-only import

Typescript 3.8 引入了 type-only import,可以在导入时只导入类型,不导入值。

1
import type { Foo } from "./foo";
 评论
评论插件加载失败
正在加载评论插件