Consider the following directory structure:
src/
├── foo.ts
├── bar.ts
├── baz.ts
├── index.ts
If foo.ts
, bar.ts
, and baz.ts
each export a default class or object, for example in foo.ts
:
export default class Foo {
x = 2;
}
Is it possible to automatically create a declaration file that defines a module named my-module
and exports foo.ts
, bar.ts
, and baz.ts
as non-defaults?
In other words, I would like tsc
to generate the following:
build/
├── foo.js
├── bar.js
├── baz.js
├── index.js
├── index.d.ts
Where index.d.ts
includes:
declare module 'my-module' {
export class Foo {
...
}
export class Bar {
...
}
export class Baz {
...
}
}
It seems that most NPM modules have a declaration file structured in a similar way.
How can I achieve this?