importing into index.d.ts is breaking my types

762 views Asked by At

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}`;

If I comment out the import then the existing types - Person, and doThing are found and work in example.ts If I keep the reference to the import then it breaks and example.ts cannot find the types for 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'.

1

There are 1 answers

0
Steve Tomlin On BEST ANSWER

Ok I found the reason: Credit: Import class in definition file (*d.ts)

My fix:

index.d.ts

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

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

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