简体   繁体   English

使用ionic2,Typescript,RollupJs,es2015模块的`lodash-es`导致TS错误

[英]TS Error with `lodash-es` using ionic2, Typescript, RollupJs, es2015 modules

I'm using lodash with the new ionic2@RC.0 project template, which includes 我在新的ionic2@RC.0项目模板中使用lodash ,其中包括

  • Typescript 打字稿
  • Rollup 卷起
  • es2015 modules es2015模块

This works for me: 这对我有用:

npm install lodash --save
npm install @types/lodash --save-dev --save-exact
// typescript
import _ from "lodash";

But apparently lodash-es is recommended with Rollup because of the tree-shaking thing. 但是显然,由于摇树,建议在Rollup使用lodash-es But when I do this: 但是当我这样做时:

npm install lodash-es --save  // instead of `lodash`
npm install @types/lodash --save-dev --save-exact
// typescript
import _ from "lodash-es";

I get a Typescript error 我收到Typescript错误

error TS2307: Cannot find module 'lodash-es'.

However, the transpiled javascript actually works and runs correctly. 但是,转译的javascript实际上可以正常运行。 What gives? 是什么赋予了?

here is my tsconfig 这是我的tsconfig

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "pretty": true,
    "target": "es5"
  },
  "filesGlob": [
    "**/*.ts",
    "!node_modules/**/*"
  ],
  "exclude": [
    "node_modules"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}

问题是没有人为lodash-es创建类型文件,因此Typescript编译器无法验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM