【发布时间】:2019-08-09 08:31:03
【问题描述】:
我有一个使用 CRA 打字稿创建的项目。
在项目的根目录下存在tsconfig.json 和一个名为types 的文件夹。在 types 文件夹中,我为在 node_modules 没有默认类型的模块创建了一个 modulename.d.ts 文件,并且在 @types\module-name 也没有任何内容。
但我在编译时收到错误。
类型错误:找不到模块“名称”的声明文件。 '/*/node_modules/thename/dist/entry.js' 隐含了一个 'any' 类型。
为什么编译器在 types 文件夹中找不到类型声明?
// .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"]
}
【问题讨论】:
标签: typescript create-react-app typescript-typings tsconfig react-tsx