typescript-library-starter
typescript-library-starter copied to clipboard
How do you include custom types?
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?
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'
.