Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
223 views
in Technique[技术] by (71.8m points)

javascript - How can I view original javscript library source code in VS Code and not the typescript version?

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.

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.

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?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...