我收到此错误:
TS7016: Could not find a declaration file for module 'faker/locale/en_CA'. '.../myproject/node_modules/faker/locale/en_CA.js' implicitly has an 'any' type.
使用此代码:
import * as faker from 'faker/locale/en_CA';
问题是,我安装了 @types/faker
,我可以看到 node_modules/@types/faker/index.d.ts
实际上包括:
declare module "faker/locale/en_CA" {
export = fakerStatic;
}
所以模块已经被声明,但是TS由于某种原因找不到它。
这是我的 tsconfig:
{
"compilerOptions": {
"strict": true,
"importHelpers": false,
"inlineSources": true,
"noEmitOnError": true,
"pretty": true,
"module": "commonjs",
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"removeComments": true,
"preserveConstEnums": false,
"sourceMap": true,
"lib": ["es2017","esnext.asynciterable"],
"skipLibCheck": true,
"outDir": "dist",
"target": "es2018",
"declaration": true,
"types" : ["node"],
"resolveJsonModule": true,
"esModuleInterop": false,
"baseUrl": ".",
"paths": {
"*": ["types/*"]
}
},
"files": [
"src/main"
],
"exclude": [
"node_modules"
]
}
我错过了什么吗?
请注意
import * as faker from 'faker';
工作得很好。
VSCode 和 PhpStorm 都可以找到 'faker/locale/en_CA'
没问题,只是 tsc
找不到。
最佳答案
尝试从 tsconfig.json 中删除 "types": ["node"]
。根据the documentation ,该行表示您不希望 TypeScript 加载除 node
之外的任何包的类型。
关于typescript - TS7016 : Could not find a declaration file for module 'faker/locale/en_CA' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51642159/