我有一个 .mdx
文件。
在 mdx.d.ts
中有以下内容:
/// <reference types="@mdx-js/loader" />
import { ComponentType } from "react";
declare module '*.mdx' {
const Component: ComponentType;
export default Component;
}
制作
import Comp from "./Comp.mdx";
抛出“TS2307:找不到模块'./Comp.mdx'或其对应的类型声明。”
但是只有以下工作:
declare module '*.mdx';
这是为什么?
tsconfig.json
:
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": ["**/*.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}