-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
error TS2385: Overload signatures must all be public, private or protected. Why? #7577
Comments
Constructor visibility is now supported in As for visibility on signatures, the type system is TypeScript is structural, it is not clear what it means to compare two types with signatures that might not match in visibility. |
Since there is no function overloading in JavaScript, there is only ever one method to call. From an api design perspective, your usecase makes sense, but as visibility modifiers in TypeScript are essentially a design time illusion, although there may possibly be support in a future version of ECMAScript, |
Accidentally hit enter: |
Are you sure? I mean, there is lots of stuff, which is just a design time illusion. What I would like to achieve with that is, that tsc checks, that I can only call public signatures from outside of a class, while I can also call private signatures from inside the class and protected ones from inside a child class. |
It is not clear there is much value for such feature vs the complexity added to the language and the implementation. |
gives:
What is this restriction needed for? Of course a possible workaround is an internal helper function:
But it is just unnecessary work and unnecessary function calls (performance, when called often).
Even worse, when i try to do this on a constructor, it complains:
Why not? I wanted to have a constructor, which is only accessible by methods inside the class and allows to specify additional parameters to the constructor, which would else hold their default values. Of course, the workaround above also works in this situation.
The text was updated successfully, but these errors were encountered: