【问题标题】:declare class in typescript with declare word [duplicate]用声明词在打字稿中声明类[重复]
【发布时间】:2020-09-12 20:52:43
【问题描述】:

declare类有什么用?而我们可以去掉declare这个词??? p>

 export declare class DialogContentBase {
        dialogTitleBar: DialogTitleBarComponent;
    }

我们可以像这样简单地定义类:

 export class DialogContentBase {
        dialogTitleBar: DialogTitleBarComponent;
    }

【问题讨论】:

    标签: javascript angular reactjs typescript


    【解决方案1】:

    Declare 用于为来自代码库外部的代码定义接口:https://dzone.com/articles/quick-tip-%E2%80%93-typescript-declare

    例如

    如果你从代码库之外的某个地方全局包含一个库并且你想使用它(例如你把它放在 index.html 中)你可以使用declare 来声明它的类型。

    你不应该在你的用例中使用它。

    【讨论】:

      猜你喜欢
      • 2017-08-12
      • 2017-06-10
      • 1970-01-01
      • 2019-02-16
      • 2018-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多