TypeScript declaration generation issues

It’s nice that TypeScript compiler (tsc) is able to generate declarations (*.d.ts files) out of TypeScript source files (*.ts), besides the standard JavaScript® output. That is very useful for component development or whenever you don’t want to include all TypeScript source code within the delivery, but only minified JavaScript® and TypeScript declarations. But there at least two problems to address with this approach:

  1. From Visual Studio®, the TypeScriptCompile build action doesn’t automatically build declaration files. You will need to add a pre-build event on the project, manually calling the compiler with the –d argument.

    for %%f in (“$(ProjectDir)\*.ts”) do tsc -d “%%f”

    This will also pre-generate *.js files in the project folder, so in this case you may remove the TypeScriptCompile build actions from *.ts source files in your project, to avoid duplicate compilation.

  2. Declarations generated by the compiler out of TypeScript files include private definitions! If you have a class with a private member, that member will be shown inside the generated declarations, and there doesn’t seem to be an easy way to hide them. Some may argue that this is actually useful to limit inheritance, and hiding won’t help from JavaScript® internal tinkering, but I still find it as an oddity and very little gain, if any.

About Sorin Dolha

My passion is software development, but I also like physics.
This entry was posted in Computers and Internet and tagged , , , , , . Bookmark the permalink.

Add a reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s