[英]Where to find the source code of @types/node
According to the instructions online, I installed Node for Typescript via the following command. 根据在线说明,我通过以下命令安装了Node for Typescript。
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
中有一些新文件。
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? 如果我没记错的话,Node.js是用JS而不是Typescript编写的,所以我需要使用那些JS源代码来调用Node.js api,而不仅仅是上面显示的Typescript定义文件,但是在哪里可以找到这些文件? What's the default location to store those JS files when I run
npm install @types/whateveritis
? 当我运行
npm install @types/whateveritis
时,存储那些JS文件的默认位置是npm install @types/whateveritis
?
The JS files that make up a module aren't handled by TS. TS不会处理组成模块的JS文件。 Node is part of the runtime environment, so it's always available.
节点是运行时环境的一部分,因此它始终可用。 Other packages would be bound in node_modules.
其他软件包将绑定在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.
导入时,类型信息与实际的模块代码结合在一起-TS编译器将找到模块名称的适当类型声明(可能来自@types)并将其引入。
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. 请记住,TS永远不会对导入的模块显式执行任何操作,它只会为编译器自己的簿记应用正确的类型信息。 Nothing is actually imported until you execute your generated javascript code and typescript is no longer relevant at that point.
在执行生成的javascript代码之前, 实际上不会导入任何内容,并且此时打字稿不再相关。
Note that you did not install node by doing that, you will still need to install any modules separately through NPM. 请注意,您这样做并不是安装节点,您仍然需要通过NPM单独安装所有模块。 See earlier point of node always being available.
请参阅节点的早期点始终可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.