typescript-library-starter icon indicating copy to clipboard operation
typescript-library-starter copied to clipboard

How do you include custom types?

Open a9udn9u opened this issue 6 years ago • 1 comments

If your exposed API returns a custom type defined by yourself, say in "typings/types.d.ts", and you specify this file in tsconfig.json, typescript compiler will not automatically include this custom type in the generated index.d.ts, how do you export the custom type?

a9udn9u avatar Mar 21 '18 01:03 a9udn9u

I was about to ask a similar question. Please, correct me if I am wrong: with the current tsconfig.json, tsc automatically infers the typings and put them in dist/index.d.ts. But how if I want to add my custom typings like @a9udn9u said?

For example, I want to make available to any customer of my library a Dog type. Then, in typings/index.d.ts (outside src dir) I put:

declare module "hwrld" {
    export interface Dog {
        name: string;
        breed: string;
        age: number;
    }
}

But when I build with tsc the custom type doesn't get compiled in the dist/ directory. I suppose that's why testing the example-consumer throws the below error: Module '"hwrld"' has no exported member 'Dog'.

minicatsCB avatar Jun 12 '23 19:06 minicatsCB