-
Notifications
You must be signed in to change notification settings - Fork 12.8k
don't support multiple constructors? #16518
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
Comments
Did you mean constructor overloads? class Person {
private name: string;
constructor();
constructor(name: string);
constructor(name?: string) {
this.name = name;
}
} Or what you mean is something just like C++ does? See #12041 (comment). |
I mean, Multiple constructor implementations, just like below: class Person {
private name: string;
constructor() {}
constructor(name: string) {
this.name = name;
}
} as you see, there are two implementations |
I think multi-implementations should be duplicate of #12041. EDIT: EDIT: See TypeScript Docs: Function - Overloads for more about overloads. |
thank you! |
I don't know why the constructor can't be more. |
Because Javascript itself does not allow, and TS does not want to add more runtime behavior (see TS design goal). |
TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)
Code
Expected behavior:
compile pass
Actual behavior:
error: Multiple constructor implementations are not allowed.
The text was updated successfully, but these errors were encountered: