Replies: 3 comments
-
|
声明全局变量的 |
Beta Was this translation helpful? Give feedback.
-
|
可以通过 foo = 123; // Error: 'foo' is not defined和: declare var foo: any;
foo = 123; // allow如果一个文件有扩展名 |
Beta Was this translation helpful? Give feedback.
-
|
其实我有个问题,声明全局变量不用declare也可以啊,只要没import或者export就是全局变量。所以我觉得declare的作用不是用来声明全局变量的,而是用来声明变量的,因为declare的变量是不能赋值的(Initializers are not allowed in ambient contexts)。另外.d.ts中每个根级别的声明都必须以 declare 关键字作为前缀。第三点,declare用来修饰namespace的话,namespace中的子属性都不用export 就可以直接访问。第四点,declare 在局部作用域(也必须在局部作用域)可以接global声明全局变量 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
declare 关键字有什么作用?
Beta Was this translation helpful? Give feedback.
All reactions