Search code examples
typescripttsc

tsc --declaration: how to hide private methods and attributes?


Running tsc with --declaration option generates the .d.ts file with all the declaration, private included.

Is there a way to produce a .d.ts file with only exported types and, for classes, only public methods and attributes?


Solution

  • It's not possible.

    Typescript keeps privates in generated .d.ts files to support further inheritance.

    Because there is no such thing as 'private' in JS, declaring a type that derives from a d.ts type with stripped out privates could cause problems if you accidentally will have a name collision in your child class. That will be very difficult to find and fix.