javascript.d.ts

Where can I find source definitions in javascript?


I come from java background and similar languages where if I want to find the source of some built-in function I just press ctrl-left click on it and in newer IDEs it shows the source which is written in the same language as the language I am programming in. In javascript, however, it's a bit different - the source code is displayed as *.d.ts. I found that sometimes to solve this problem VS Code has the option to go to "Source Definition" but it doesn't work for everything. For example, if I want to see what the right definition of the Promis object is (in javascript), it just doesn't show me what I want

Maybe this can somehow be set in IDE, or am I missing something?


Solution

  • What you are looking at are typescript type definition files, basically an interface like in java, but just the type. It is not source code.

    If you want to know how a function is really implemented you need to look into browser source code (or the source code of whatever environment you plan to run your javascript in). Some functionally is not even implemented as javascript but natively in C++ in most browsers.

    As browser codebases are massive projects that tend to be hard to understand, I recommend reading the documentation instead for the functions that interest you, for promises: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise