0

我有一个.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";

throw "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"]
}
4

1 回答 1

0

/// 导入 { ComponentType } from "react";

不知道为什么,但删除导入语句使其工作。将 ComponentType 更改为任何。

于 2021-11-23T09:31:35.213 回答