在 Visual Studio 代码中转到 Typescript 源定义而不是编译定义

Go to Typescript Source Definition instead of Compiled Definition in Visual Studio Code

我正在使用 Visual Studio 代码开发一个 typescript 项目,其中包含多个结构如下的 npm 包:

当我右键单击导入的对象并选择 "Go to Definition" 或单击 F12 或按住 CTRL 单击对象时,Visual Studio 代码打开相应的.d.ts 文件在 /dist

但是,我希望VSCode打开/src

中对应的.ts文件

是否可以更改此行为,因为手动搜索源文件真的很烦人。

我已经创建了 git 存储库,因此您可以自己尝试: https://github.com/flolude/Whosebug-typescript-go-to-definition

TypeScript 2.9 引入了一个名为 declarationMap 的编译器选项。根据发行说明:

Enabling --declarationMap alongside --declaration causes the compiler to emit .d.ts.map files alongside the output .d.ts files. Language Services can also now understand these map files, and uses them to map declaration-file based definition locations to their original source, when available.

In other words, hitting go-to-definition on a declaration from a .d.ts file generated with --declarationMap will take you to the source file (.ts) location where that declaration was defined, and not to the .d.ts.

submitted a PR 在您的示例存储库中启用此设置。