“声明"在“导出声明类操作"中有什么作用? [英] What does 'declare' do in 'export declare class Actions'?

查看:29
本文介绍了“声明"在“导出声明类操作"中有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们需要声明中的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屋!

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