gpt4 book ai didi

javascript - 转到 Typescript Source Definition 而不是 Visual Studio Code 中的 Compiled Definition

转载 作者:搜寻专家 更新时间:2023-10-30 20:58:23 28 4
gpt4 key购买 nike

我正在使用 Visual Studio Code 开发一个 typescript 项目,包括多个结构如下的 npm 包:

  • 源代码:/src/index.ts
  • 编译后的代码:/dist/...

当我右键单击导入的对象并选择“转到定义”或单击 F12 或按住 CTRL 单击对象时,Visual Studio Code 打开/dist

中对应的 .d.ts文件

vscode go to definition vscode open .d.ts

但是,我想让VSCode在/src中打开对应的.ts文件

.ts file

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

我已经创建了 git repo,所以你可以自己试试: https://github.com/flolude/stackoverflow-typescript-go-to-definition

  • 您只需运行 yarn bootstrap 即可重现问题。

最佳答案

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在您的示例存储库中启用此设置。

关于javascript - 转到 Typescript Source Definition 而不是 Visual Studio Code 中的 Compiled Definition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57697571/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com