It is possible to jump to TS source files inside node_modules

When I ctrl+click some type definitions that belong to lib present in node_modules, PHPStorm opens some *.d.ts file with type definitions. Is there some way, or maybe plugin, to peek actual typescript (or javascript) sources of libraries?

1
4 comments

Created example setup and realized it works here.
In my project, there were some missing .d.ts files, that is why it was not proper working.

After proper setup it works now:

- proper mark as "source folder" of node_modules/mylibrary
- generate .d.ts, copy .ts source code inside of node_modules/mylibrary
- create dummy tsconfig.json file inside of node_modules/mylibrary with baseUrl config, and jsx, so IntelliJ does not mark it red and can navigate inside

2

In JavaScript files:

  • If type definitions are installed in the node_modules/@types folder, IDE tries to navigate to the JavaScript sources of the library when using Ctrl+click. Please note that this only works for symbols that are defined as classes, variables or functions (and not interfaces or types) in the .d.ts file.
  • If type definitions are available inside the module, PhpStorm does not index the JavaScript source by default and, thus, can't to navigate to them. To index these files, please use Navigate | Implementation first and answer Yes when the question pops up:

 



After that, Ctrl+click will try to take you to the library sources. The same limitation regarding the kind of definition in .d.ts applies.

In TypeScript files:

  • Go to declaration will take you to the d.ts file or .ts sources if they could be mapped.
  • Go to implementation will take you to the .js sources of the module if they could be located and mapped.
1

So jumping to .d.ts files and .ts files works fine, but when a .tsx file is provided,instead  it jumps to .d.ts files and not .tsx file.

@Jetbrains please fix it. This would be awesome!

0

Please share a project the issue can be repeated with

0

Please sign in to leave a comment.