Skip to content

Commit ad7454b

Browse files
committed
设置偏好 type 自动导入
1 parent 2ac9e70 commit ad7454b

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

zh/release-notes/typescript-5.3.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,34 @@ TypeScript 5.3 现在更仔细地检查 `super` 属性访问/方法调用,以
304304
TypeScript 的内嵌提示支持跳转到类型定义!
305305
这便利在代码间跳转变得简单。
306306

307-
更多详情请参考[PR](https://github.com/microsoft/TypeScript/pull/55141)
307+
更多详情请参考[PR](https://github.com/microsoft/TypeScript/pull/55141)
308+
309+
## 设置偏好 `type` 自动导入
310+
311+
之前,当 TypeScript 为类型自动生成导入语句时,它会根据配置添加 `type` 修饰符。
312+
例如,当为 `Person` 生成自动导入语句时:
313+
314+
```ts
315+
export let p: Person
316+
```
317+
318+
TypeScript 通常会这样生成 `Person` 导入:
319+
320+
```ts
321+
import { Person } from "./types";
322+
323+
export let p: Person
324+
```
325+
326+
如果设置了 `verbatimModuleSyntax`,它会添加 `type` 修饰符:
327+
328+
```ts
329+
import { type Person } from "./types";
330+
331+
export let p: Person
332+
```
333+
334+
然而,也许你的编辑器不支持这些选项;或者你偏好显式地使用 `type` 导入。
335+
336+
[最近的一项改动](https://github.com/microsoft/TypeScript/pull/56090),TypeScript 把它变成了针对编辑器的配置项。
337+
在 Visual Studio Code 中,你可以在 "TypeScript › Preferences: Prefer Type Only Auto Imports" 启用该功能,或者在 JSON 配置文件中的 `typescript.preferences.preferTypeOnlyAutoImports` 设置。

0 commit comments

Comments
 (0)