Skip to content

Private variables in definition files #1867

Closed

Description

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

Activity

  1. RyanCavanaugh commented on Jan 30, 2015

    @RyanCavanaugh
    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.

  2. paztis commented on Jan 31, 2015

    @paztis
    Author

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

  3. added
    Question
    on Feb 2, 2015
  4. georgehdd commented on Apr 12, 2016

    @georgehdd

    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.

  5. RyanCavanaugh commented on Apr 12, 2016

    @RyanCavanaugh
    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.

  6. locked and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions