Angular2:Lodash 工作但触发 Typescript 错误

Angular2 : Lodash working but triggers a Typescript error

我确实尝试在我的 angular2 项目中导入 lodash。它工作正常,但我的日志中一直出现以下错误:

TS2307 Cannot find module 'lodash'.
[error] import * as _ from "lodash"

但是,我使用它没有任何问题。我是否必须更改任何 tsconfig 以防止这种情况发生?

您需要向 TypeScript 声明外部模块可以为您进行类型检查。

快速修复

typings install lodash --global --save