如何在 VS Code 中查看原始 javscript 库源代码而不是 typescript 版本? [英] How can I view original javscript library source code in VS Code and not the typescript version?

查看:44
本文介绍了如何在 VS Code 中查看原始 javscript 库源代码而不是 typescript 版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习 Express JS,我是通过单击 IDE 的转到定义"并跟踪每个方法/函数来学习库的人.

I just started to learn Express JS and I am someone who learns the library by clicking "Go to definition" of IDE's and tracing each method/function.

但是当我点击 javascript 文件的转到定义"时,Visual Studio Code 将我带到 index.d.ts 文件,这是打字稿版本.这对我没有帮助,因为这无助于我理解库的底层架构.

But when I click on "Go to definition" of javascript files, Visual Studio Code takes me to the index.d.ts file which is the typescript version. This is no help to me as this doesn't help me understand the underlying architecture of libraries.

如何从 VS Code 中查看原始库源代码?如果没有,Github(或任何其他来源)中是否有类似的功能可以单击将我带到方法定义的方法调用?

How can I view the original library source code from VS Code? If not, is there any similar feature in Github (or any other source) to click a method call that will take me to the method definition?

谢谢

推荐答案

如果你的 tsconfig.json"allowJs": true"maxNodeModuleJsDepth" 设置为足够大的数字,然后您卸载类型声明,然后单击转到定义"将带您到 TypeScript 对 JavaScript 中定义的最佳猜测,这可能不好用于从未设计为可静态分析的 JavaScript 代码(例如,我在 Express 方面做得并不好).对于直接在包中包含类型声明而不是具有可以卸载的单独 @types 包的 JavaScript 包,您必须手动复制 JavaScript 源代码(而不是类型声明)进入项目的子目录并设置 baseUrlpaths 选项,以便 TypeScript 找到它.

If your tsconfig.json has "allowJs": true and "maxNodeModuleJsDepth" set to a sufficiently large number, and you uninstall the type declarations, then clicking "Go to definition" will take you to TypeScript's best guess of the definition in the JavaScript, which may be no good for JavaScript code that was never designed to be statically analyzable (e.g., I didn't get very far with Express). For a JavaScript package that includes type declarations directly in the package instead of having a separate @types package that you can uninstall, you'll have to manually copy the JavaScript source code (and not the type declarations) into a subdirectory of your project and set up the baseUrl and paths options so that TypeScript finds it.

这个问题是为了转到定义"带你到 JavaScript即使安装了类型声明.

This issue is for "Go to definition" to take you to the JavaScript even when the type declarations are installed.

这篇关于如何在 VS Code 中查看原始 javscript 库源代码而不是 typescript 版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆