问题描述
限时送ChatGPT账号..为什么我们需要声明中的declare
?
Why do we need the declare
in the statement?
export declare class Actions {
...
}
推荐答案
找到了我要找的东西:
声明与 var
var
创建一个新变量.declare
用于告诉 TypeScript 该变量已在别处创建.如果您使用 declare
,则不会在生成的 JavaScript 中添加任何内容 - 它只是对编译器的提示.
var
creates a new variable. declare
is used to tell TypeScript that the variable has been created elsewhere. If you use declare
, nothing is added to the JavaScript that is generated - it is simply a hint to the compiler.
例如,如果您使用定义了 var externalModule
的外部脚本,您将使用 declare var externalModule
来提示 externalModule
的 TypeScript 编译器代码>已经设置
For example, if you use an external script that defines var externalModule
, you would use declare var externalModule
to hint to the TypeScript compiler that externalModule
has already been set up
这篇关于“声明"在“导出声明类操作"中有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论