Skip to content

Commit 4465b42

Browse files
committed
优化进行中的类型兼容性检查
1 parent b8ffae1 commit 4465b42

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

zh/release-notes/typescript-5.2.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,3 +761,54 @@ TypeScript 5.2 现在具有一种重构方法,可以将变量的内容内联
761761
请注意,这可能会导致初始化程序的副作用在不同的时间运行,并且运行的次数与变量的使用次数相同。
762762

763763
更多详情请查看 [PR](https://github.com/microsoft/TypeScript/pull/54281)
764+
765+
## 可点击的内嵌参数提示
766+
767+
内嵌提示可以让我们一目了然地获取信息,即使它在我们的代码中不存在 —— 比如参数名称、推断类型等等。
768+
在 TypeScript 5.2 中,我们开始使得与内嵌提示进行交互成为可能。
769+
例如,在 Visual Studio Code Insiders 中,您现在可以点击内联提示以跳转到参数的定义处。
770+
771+
更多详情请查看 [PR](https://github.com/microsoft/TypeScript/pull/54734)
772+
773+
## 优化进行中的类型兼容性检查
774+
775+
由于 TypeScript 采用的是结构化的类型系统,通常需要比较类型成员;
776+
然而,递归类型会造成一些问题。例如:
777+
778+
```ts
779+
interface A {
780+
value: A;
781+
other: string;
782+
}
783+
784+
interface B {
785+
value: B;
786+
other: number;
787+
}
788+
```
789+
790+
在检查 `A` 是否与 `B` 类型兼容时,TypeScript 会检查 `A``B``value` 的类型是否兼容。
791+
此时,类型系统需要停止进一步检查并继续检查其他成员。
792+
为此,类型系统必须跟踪两个类型是否已经相关联。
793+
794+
此前,TypeScript 已经保存了配对类型的栈,并迭代检查类型是否已经关联。
795+
当这个堆栈很浅时,这不是一个问题;但当堆栈不是很浅时,那就是个[问题](https://accidentallyquadratic.tumblr.com/)了。
796+
797+
在 TypeScript 5.2 中,一个简单的 `Set` 就能跟踪这些信息。
798+
在使用了 drizzle 库的测试报告中,这项改动减少了超过 33% 的时间花费!
799+
800+
```
801+
Benchmark 1: old
802+
Time (mean ± σ): 3.115 s ± 0.067 s [User: 4.403 s, System: 0.124 s]
803+
Range (min … max): 3.018 s … 3.196 s 10 runs
804+
805+
Benchmark 2: new
806+
Time (mean ± σ): 2.072 s ± 0.050 s [User: 3.355 s, System: 0.135 s]
807+
Range (min … max): 1.985 s … 2.150 s 10 runs
808+
809+
Summary
810+
'new' ran
811+
1.50 ± 0.05 times faster than 'old'
812+
```
813+
814+
更多详情请查看 [PR](https://github.com/microsoft/TypeScript/pull/55224)

0 commit comments

Comments
 (0)