【问题标题】:Typescript's declare module with body and without打字稿声明有主体和没有主体的模块
【发布时间】:2021-06-03 16:54:13
【问题描述】:

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

【问题讨论】:

    标签: typescript mdxjs


    【解决方案1】:

    /// 从“反应”导入 { ComponentType };

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多