是否可以通过导入使用绝对路径(而非相对路径)的方式配置 vs 代码?

Is it possible to configure vs code such way that import will use absolute path (not relative)?

VSCode 上次更新后现在知道如何自动添加导入了。但是它添加了使用相对路径 - 知道这是否可以某种方式配置吗?

如果您使用的是 VS Code 1.24 和 TypeScript >= 2.9,则它是可配置的。

来自release notes,

Preferences for auto imports and generated code

You can now explicitly specify the quote and path styles that VS Code uses for auto imports and other generated JavaScript and TypeScript code.

[...]

The javascript.preferences.importModuleSpecifier and typescript.preferences.importModuleSpecifier settings specify the type of path to use for imports.

Valid values are:

  • "relative" to the file location.
  • "non-relative" based on the baseUrl configured in your jsconfig.json / tsconfig.json.
  • "auto" to infer the shortest path type.

These new preferences require TypeScript 2.9+.