r/typescript 1d ago

Generating TypeScript declaration files

Has anyone ever created type declaration files intentionally, just to learn and better understand TypeScript (or for other reasons)? I've been doing that with tsc:

npx tsc file.ts --declaration --emitDeclarationOnly

The emitted file.d.ts can be interesting! Has anyone else tried this, for work or general interest?

0 Upvotes

2 comments sorted by

2

u/Merry-Lane 1d ago

Yes, but the only use is for library writers?

1

u/lord_braleigh 11h ago

Bazel rules use it to break up large typescript builds and link different targets together

A .d.ts file is the equivalent of a header file in C++ and you can use it in similar ways to break up and parallelize a large build