Typescript 3.0.1编译器选项类型无法识别根

时间:2018-08-16 14:00:06

标签: typescript

我正在尝试编译一个基本项目,并在我的库中包含lodash。根据Typescript 3.0文档,这应该可以工作。

package.json

{ 
 ...
 "dependencies": {
   "lodash": "4.17.10",
   "npm-run-all": "4.1.2",
   "typescript": "3.0.1"
  }
 ...
}

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitAny": false,
    "removeComments": true,
    "preserveConstEnums": true,
    "sourceMap": true,
    "outDir": "./dist/out-tsc",
    "typeRoots": [
      "./node_modules/@types/"
    ]
  },
  "include": [
    "src/**/*.ts",
    "node_modules/@types"
  ],
  "exclude": [
    "node_modules",
    "**/*.spec.ts"
  ]
}

types也会发生同样的事情。根据google搜索,我的组件必须包含typeRoots才能使用typeslodash。我想念什么?

1 个答案:

答案 0 :(得分:0)

我的答案:

{
  "compilerOptions": {
    "strict": true,
    "module": "commonjs",
    "target": "ESNext",
    "noImplicitAny": true,
    "typeRoots": ["app/types/*","./node_modules/@types","../../node_modules/@types",],
     "types":["node","jest"],  
    "moduleResolution": "node",
    "baseUrl": "./",
    "sourceMap": false,
    "esModuleInterop": true,
    "experimentalDecorators":true,
    "forceConsistentCasingInFileNames":true,
    "strictPropertyInitialization":false,
    "outDir": "build"

  },
  "include": ["./app/**/*"],
  "exclude": ["node_modules", "./__tests__/*"]
}