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

Support making a constructor private (while not making the whole class private) #2761

Open
mtaran-google opened this issue Dec 14, 2017 · 3 comments

Comments

@mtaran-google
Copy link
Contributor

e.g. then you could expose a class that can only be used in type annotations, or for its static methods (which could include factory methods that call out to the constructor).

@shicks
Copy link
Member

shicks commented May 18, 2018

I think this issue is slightly misconceived. Indeed, I had previously understood @private on a class to mean that all references to the class should cause a visibility error, but I'm getting reports that the actual current behavior is that there's no way to make a class (i.e. type refs or static methods) private, and that @private on the class only applies to calling the constructor.

But the gist is still correct, these are two separate concepts and we need to be able to express then both.

@mtaran-google
Copy link
Contributor Author

FWIW, we use typescript now, which does support this cf microsoft/TypeScript#6885 :)

@nreid260
Copy link
Contributor

nreid260 commented Oct 11, 2018

Visibility checks now respect visibility annotations on ES6 class constructors.

Visibility annotations on constructors refer to the invocability of the constructor (including use in extends clauses). It does not effect the ability to reference the class in any other context (e.g. instanceof, assignment, parameter passing). The variable used to reference the constructor is irrelevant to the check, only the type matters.

Constructor visibility is selected in descending preference by: (1) annotation directly on the definition, (2) annotation in the @fileoverview, (3) @public by default. It is not inherited from superclass definitions. It is not inferred from class definitions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants