typescript - Angular2-Webpack-Typescript - 第 3 方库

标签 typescript angular webpack immutable.js

我已经开始了一个美丽的种子项目:https://github.com/AngularClass/angular2-webpack-starter

而且我一直坚持使用第 3 方模块。有人可以帮助/解释如何正确地向该项目添加/使用外部模块吗?

例如,我使用以下方式添加“不可变”:

npm install immutable --save

在那之后,我试图在一个组件中链接那个模块:

import * as immutable from 'immutable';
import {List} from 'immutable';
import Immutable = require('immutable');

没有任何帮助,它总是返回 TS2307:找不到模块“immutable”。例如,“moment”也是如此。

最佳答案

您需要将一个类型文件添加到位于 node_modules\immutable\dist\immutable.d.ts 中的项目中。您需要在您的项目中引用它。它应该看起来像这样:

/// <reference path="node_modules/immutable/dist/immutable.d.ts" />
import * as immutable from 'immutable';
import {List} from 'immutable';
import Immutable = require('immutable');

暂时可以在 DefinitelyTyped 找到类型.我建议使用 tsd安装它们。

如果您遇到一个您想使用的库,但找不到任何类型,您可以查看 this question一个简单的方法仍然可以使用它。您只是不会获得任何 Typescript 的好处。

关于typescript - Angular2-Webpack-Typescript - 第 3 方库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35638027/

相关文章:

angular - 如何取消订阅 ngrx/store?

javascript - Webpack 未加载的静态图像

javascript - Webpack 服务器未记录的属性是否存在?

html - !default css font-family 特异性标签

javascript - 与 typescript react 来初始化空状态的正确方法是什么

css - 如何有条件地更改 Angular 组件中的样式 url?是否可以?

node.js - sequelize 和 postgres 中关联表中的多个值

ios - 在高分辨率下默认关闭 ionic 菜单 | Angular 和 ionic 4

typescript - Cloud Functions FieldValue 增量 Firestore 中的 TypeError

typescript 属性