我有一个使用 CRA 打字稿创建的项目。
在项目的根目录下存在tsconfig.json
一个名为types
. 在 types 文件夹中,我modulename.d.ts
为在 node_modules 处没有默认类型的模块创建了一个文件,并且在@types\module-name
.
但我在编译时得到错误。
类型错误:找不到模块“名称”的声明文件。'/*/node_modules/thename/dist/entry.js' 隐含了一个 'any' 类型。
为什么编译器在类型文件夹中找不到类型声明?
// .d.ts
declare module 'foo-react' {
import * as React from 'react';
// ...
}
这是tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": { "*": ["types/*"] },
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"plugins": [{ "name": "typescript-tslint-plugin" }],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve"
},
"include": ["src"]
}