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

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

问题描述

我刚开始学习Express JS,我是通过点击IDE的Go to definition并跟踪每个方法/函数来学习库的人。

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设置为足够大的数字,然后卸载类型声明,然后单击Go定义将带您进入TypeScript对JavaScript中定义的最佳猜测,这对于从未设计为静态可分析的JavaScript代码可能没有用(例如,我对Express没有太大的帮助)。对于直接在包中包含类型声明而不是包含可以卸载的单独 @types 包的JavaScript包,您必须手动复制JavaScript源代码(而不是类型声明)进入项目的子目录并设置 baseUrl 路径选项,以便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天全站免登陆