【问题标题】:What are typings and @types in angular2?angular2 中的类型和@types 是什么?
【发布时间】:2017-10-25 18:21:34
【问题描述】:

谁能帮我理解angular2中的类型和@types是什么?

如何定义类型以及如何在 angular2 中将 @types 与 webpack 一起使用?

【问题讨论】:

  • my answer 有什么不清楚的地方吗?不要忘记,如果有帮助,您可以接受答案

标签: angular typescript typescript-typings


【解决方案1】:

Typescript 语言作为 JavaScript 的超集,使用 type declaration files 在编译期间提供所需的类型检查。

@types 名称只是一个作用域前缀名称,有助于对 NPM 上可用的所有类型定义进行分组。

查看 Angular “Typescript 配置”文档了解更多详情:

https://angular.io/docs/ts/latest/guide/typescript-configuration.html

【讨论】:

    【解决方案2】:

    输入只是declaration files 组合在一起。每个声明文件都定义了编译期间可用的符号(接口、值、类等)。这是类型检查和智能感知所必需的。当您编写以下内容时:

    export declare class AComponent { }
    

    你是说有 AComponent 类,所以当你使用它时编译器不会抱怨:

    const o = new AComponent();
    

    @types 只是一个命名空间npm repository,其中存储了许多类型(声明文件)。

    【讨论】:

      猜你喜欢
      • 2016-06-28
      • 2017-04-14
      • 1970-01-01
      • 2019-07-22
      • 2018-07-11
      • 2017-02-11
      • 1970-01-01
      • 2016-12-29
      • 2018-06-21
      相关资源
      最近更新 更多