导入 index.d.ts 破坏了我的类型

importing into index.d.ts is breaking my types

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "./",
    "target": "es6",                          
    "module": "commonjs",                    
    "declaration": true,                   
    "strict": true,                          
    "esModuleInterop": true,                  
    "forceConsistentCasingInFileNames": true, 
    "typeRoots": [
      "node_modules/@types",
      "@types"
    ],
    "paths": {
      "@types/*": ["@types/*"]
    },
  },
  "exclude": ["node_modules"],
  "include": ["./*", "@types"]
}

@types/index.d.ts

import { ExecException } from 'child_process';
type error = ExecException | null;

interface Person {
  is: boolean;
  str: string;
}

type doThingX = (is: boolean) => boolean;

example.ts

const jon: Person = {
  is: 'hello world'
}

const doThing: TdoThing = x => `${x}`;

如果我注释掉导入,那么现有类型 - Person 和 doThing 会被发现并在 example.ts 中工作 如果我保留对导入的引用,那么它会中断并且 example.ts 无法找到 Person of doThing 的类型。

Cannot find name 'Person'.ts(2304) Exported variable 'jon' has or is using private name 'Person'.ts(4025)

Cannot find name 'TdoThing'.ts(2304) Exported variable 'doThing' has or is using private name 'TdoThing'.

好的,我找到原因了: 信用:

我的修复:

index.d.ts

type error = import('child_process').ExecException | null;

interface Person {
  is: boolean;
  str: string;
}

type TdoThing = (is: boolean) => boolean;