Searene
Searene

Reputation: 27594

Where to find the source code of @types/node

According to the instructions online, I installed Node for Typescript via the following command.

npm install @types/node --save-dev

I found that there were some new files in the directory node_modules after running the above command.

node_modules
    @types
        node
            index.d.ts
            package.json
            README.md
            types-metadata.json

If I recall correctly, Node.js was written in JS instead of Typescript, so I need to use those JS source codes to invoke Node.js api, instead of just the Typescript definition file shown above, but where can I find those files? What's the default location to store those JS files when I run npm install @types/whateveritis?

Upvotes: 0

Views: 398

Answers (1)

Paarth
Paarth

Reputation: 10377

The JS files that make up a module aren't handled by TS. Node is part of the runtime environment, so it's always available. Other packages would be bound in node_modules. The type information is married with the actual module code when you do an import -- the TS compiler will find the appropriate type declaration for a module name (potentially from @types) and bring that in.

Keep in mind that TS never explicitly does anything with the modules you import, it just applies the proper type info for the compiler's own bookkeeping. Nothing is actually imported until you execute your generated javascript code and typescript is no longer relevant at that point.

Note that you did not install node by doing that, you will still need to install any modules separately through NPM. See earlier point of node always being available.

Upvotes: 1

Related Questions