Automatically generating TypeScript declaration files from your own .TS files during compile
Posted: (EET/GMT+2)
TypeScript is a very nice alternative to plain JavaScript, and I've started using it in all my web projects with the aim of avoiding pure JavaScript in favor of TypeScript. Now, the more complex your solutions get, the more TypeScript code (and classes) you have. Soon enough, this leads to a need to automatically generate type definitinion files (.d.ts files) from your own .ts files.
Happily enough, there's a switch in the compiler to generate these files automatically during compile. This switch is called "--declaration" (or just "-d") and can be used both from the command line and from the newer tsconfig.json configuration file.
Here's an example:
{
"compilerOptions": {
...
"declaration": true,
...
},
...
}
When this option is enabled, each .TS file you have, will automatically get an accompanying .D.TS file when you save or compile (build) your project in Visual Studio.
Hope this helps!