代码之家  ›  专栏  ›  技术社区  ›  Raffaele

TS2304:当types.d.ts导出某些内容时,找不到名称ENDPOINT

  •  0
  • Raffaele  · 技术社区  · 1 年前

    我有以下 tsconfig.json 在我的Electron Forge/Vite项目中:

    {
      "compilerOptions": {
        "target": "ESNext",
        "module": "commonjs",
        "allowJs": true,
        "skipLibCheck": true,
        "esModuleInterop": true,
        "noImplicitAny": true,
        "sourceMap": true,
        "baseUrl": ".",
        "outDir": "dist",
        "moduleResolution": "node",
        "resolveJsonModule": true
      },
      "include": ["src"]
    }
    

    以及中的一些类型定义 src/types.d.ts :

    declare const ENDPOINT: string
    declare type Api = {
      getBalance: (userid: string) => number
    }
    

    我的应用程序代码 src/main.ts 自动检测的定义 ENDPOINT ,但如果我使用 export type Api 而不是 declare type Api 在里面 src/types.d.ts 。错误为:

    TS2304: Cannot find name 'ENDPOINT'.
    

    请注意,该应用程序运行良好,只是IDE中的类型检查失败。因此,我的IDE建议 import {ENDPOINT} from './types' 但如果我这样做 TS2304 import 执行:

    Binding rvalue (Note that you need plugins to import files that are not JavaScript)
    

    怎么回事?我想以某种方式使用 export 关键字删除 types.d.ts 从typechecker根并使其成为一个模块;但是当我稍后导入它时,工具链没有配置为识别 .d.ts 文件扩展名,因此导入失败。不幸的是,这些只是我的猜测,在文档中找不到,我只是偶然发现了它。为什么单身 出口 破坏一切?

    0 回复  |  直到 1 年前