Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private variables in definition files #1867

Closed
paztis opened this issue Jan 30, 2015 · 4 comments
Closed

Private variables in definition files #1867

paztis opened this issue Jan 30, 2015 · 4 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@paztis
Copy link

paztis commented Jan 30, 2015

When I produced definition files (.d.ts) for my projects, private variables of classes are also present.

Most of the time, I use internal libraries that require others definition files (jquery.d.ts for example), or definition files that are not present in lib.d.ts (Promises.d.ts and TouchEvent.d.ts for example).

But as I use private variables in my classes for wich the type is only defined in these definition files, my project generated definition file contains these types.

So without publish all the other .d.ts files with my project one, it is unusable.

Is there a way to manage it ? Or just remove the private variables to prevent these cases ?

Thanks

@RyanCavanaugh
Copy link
Member

But as I use private variables in my classes for wich the type is only defined in these definition files, my project generated definition file contains these types.

Can you clarify? When the compiler generates a .d.ts for a class, it doesn't put type annotations on private members, so this shouldn't be a problem.

@paztis
Copy link
Author

paztis commented Jan 31, 2015

Indeed, I had not noticed that they were not typed.
I must have some public variables referencing these types.

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Feb 2, 2015
@georgehdd
Copy link

A year later: privates are still generated in d.ts. Why are they there ? what is their added values ?
This forces my class to be treated as a nominal type instead of structural type.

@RyanCavanaugh
Copy link
Member

It's absolutely necessary to have privates in generated .d.ts files. Otherwise you could derive from that class, declare a private of your own with the same name, and unknowingly stomp on your base class's private variable value. That failure mode would be very, very difficult to debug.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants