什么是Node.js中的declare var? [英] What is declare var in Node.js?

查看:2799
本文介绍了什么是Node.js中的declare var?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此nodejs代码中,

in this nodejs code,

declare var process: NodeJS.Process;
declare var global: NodeJS.Global;
declare var console: Console; 
declare var __filename: string;
declare var __dirname: string;

...

什么是'declare var'和'var'之间的区别?

What's the difference between 'declare var' and 'var'?

当我查看谷歌搜索时,我得到运行时一词。

When I look up on the googling, I get the word runtime.

wiki说运行时是计算机程序运行时的一个操作....

wiki says runtime is an operation while a computer program is running....

但我无法理解。

和第1行,process之后的:是什么意思,然后是NodeJS.Process?

and line 1, what does it mean by ":" after "process" and then "NodeJS.Process"?

这是什么意思process等于NodeJS.Process?

Is that mean "process" is equal "NodeJS.Process"?

也是第4行,__ filename之后的:是什么意思,然后是string?

also line 4, what does it mean by ":" after "__filename" and then "string"?

这是否意味着__filename等于string?

Is that mean "__filename" is equal "string"?

谢谢你。

推荐答案

使用时:

var process: NodeJS.Process;

您正在创建名为 process 的变量(没有定义值)并告诉TypeScript编译器为分配强制执行 NodeJS.Process 类型。

You are creating a variable named process (with no value defined) and telling the TypeScript compiler to enforce the NodeJS.Process type for assignments.

当你添加声明

declare var process: NodeJS.Process;

你告诉TypeScript编译器已经一个名为<的变量code>进程,类型为 NodeJS.Process 。当你有编译器不知道的源引入的变量时,这很有用。

You are telling the TypeScript compiler that there is already a variable named process with the type NodeJS.Process. This is useful when you have variables introduced by sources that the compiler is not be aware of.

参见 TypeScript手册中的声明文件

这篇关于什么是Node.js中的declare var?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆