【问题标题】:How can I use @types dependencies in my Angular 2 application?如何在 Angular 2 应用程序中使用 @types 依赖项?
【发布时间】:2017-02-22 00:22:03
【问题描述】:

我已经使用“npm install @types/bootstrap --save”安装了 Twitters 引导程序。我的 package.json 依赖项如下所示:

 "dependencies": {
    "@angular/common": "~2.4.0",
    "@angular/compiler": "~2.4.0",
    "@angular/core": "~2.4.0",
    "@angular/forms": "~2.4.0",
    "@angular/http": "~2.4.0",
    "@angular/platform-browser": "~2.4.0",
    "@angular/platform-browser-dynamic": "~2.4.0",
    "@angular/router": "~3.4.0",
    "@types/bootstrap": "^3.3.32",
    "@types/d3": "^4.5.0",
    "angular-in-memory-web-api": "~0.2.4",
    "core-js": "^2.4.1",
    "rxjs": "5.0.1",
    "systemjs": "0.19.40",
    "zone.js": "^0.7.4"
  }

我正在尝试对我的 app.modules 或 app.components 进行一次导入(不确定它属于哪里),但每次我添加 import { Bootstrap } from '@types/bootstrap' 时,它都会显示 localhost:3000/@types/bootstrap 未找到。

【问题讨论】:

标签: twitter-bootstrap angular twitter-bootstrap-3 npm


【解决方案1】:

您永远不会从@types 导入。这些包含其他模块的打字稿定义,而不是实际代码。所以模式是......

  1. @x/y导入
  2. tsc 试图找到 @x/y
  3. 如果@x/y 不包含类型,则tsc 会在@types/@x/y 中搜索类型

换句话说。您将需要安装引导程序并导入引导程序。通常模式是:

  1. npm install --save bootstrap
  2. npm install --save-dev @types/bootstrap

【讨论】:

  • 这已经被否决了几次。下次有人能帮我解释一下为什么吗?我很乐意研究更好的答案,但我不明白缺少什么。
猜你喜欢
  • 2016-11-14
  • 2017-08-27
  • 2017-03-18
  • 2017-01-30
  • 1970-01-01
  • 2017-11-10
  • 2016-10-03
  • 2017-12-02
  • 1970-01-01
相关资源
最近更新 更多