Private fields in declarations

Topics: General
Sep 20, 2013 at 12:00 PM
If one has a class with a private field inside a TypeScript source file, compiling it with "tsc -d ..." will also output a .d.ts file, which is great.

But why does the output declarations source also include the private field definition? I would like to have it hidden away. I know this won't limit somebody to use that field in JavaScript, and also I know that having the privates declared may limit TypeScript extenders or users to redefine them, but I think there is very little gained by this.
Developer
Sep 23, 2013 at 7:19 PM
Since the private field has important implications for assignment compatibility and subclassing we felt it was worth making sure the names of the private field was visible to avoid name conflicts and such, even more so since as you note the field is not truly private. Note that the type of the private field is not emitted in the .d.ts so it can't realistically be used intelligently unless one is looking at the corresponding .ts source to learn its type and then purposely accessing a private thing as if it were not private (in which case having the name omitted from the .d.ts seems unlikely to have dissuaded this person from doing something that is likely unsafe).