Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you include custom types? #5

Open
a9udn9u opened this issue Mar 21, 2018 · 1 comment
Open

How do you include custom types? #5

a9udn9u opened this issue Mar 21, 2018 · 1 comment

Comments

@a9udn9u
Copy link

a9udn9u commented Mar 21, 2018

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?

@minicatsCB
Copy link

minicatsCB commented Jun 12, 2023

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'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants