-
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
Calling super from an overloaded constructor #21906
Comments
@sandersn any ideas on what to do here? My initial reaction was |
I tried this: // super(...args);
super();
Date.apply(this, args); It compiles, but some unit tests are now failing. I'm not sure if the failures are related or not. |
I also tried: super(...(args.slice(0, 7))); No luck, but I didn't like that solution anyways. |
assuming #4130 is fixed, you can cast to a tuple. Until then, |
@sandersn I got the same error using your branch. Do I need to tweak my above code? |
Yes, you'll need to cast to a tuple of some length that is greater than the smallest date length, but I think even You'll also need to build Typescript yourself and compile from |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.8.0-dev.20180211
(Tested in the above version, but found in 2.7.1)
Search Terms:
overload constructor super
super expected arguments got 0 or more.
Code:
Expected behavior:
Code compiles without error.
Actual behavior:
Error:
Expected 0-7 arguments, but got 0 or more.
Playground Link:
FYI it seems a bit extreme that it just puts the source in the URL, but here it is:
https://www.typescriptlang.org/play/#src=class%20MyDate%20extends%20Date%20%7B%0D%0A%0D%0A%20%20public%20constructor()%3B%0D%0A%20%20public%20constructor(vd%3A%20VarDate)%3B%0D%0A%20%20public%20constructor(value%3A%20Date)%3B%0D%0A%20%20public%20constructor(value%3A%20number)%3B%0D%0A%20%20public%20constructor(value%3A%20string)%3B%0D%0A%20%20public%20constructor(year%3A%20number%2C%20month%3A%20number%2C%20date%3F%3A%20number%2C%20hours%3F%3A%20number%2C%20minutes%3F%3A%20number%2C%20seconds%3F%3A%20number%2C%20ms%3F%3A%20number)%3B%0D%0A%20%20public%20constructor(...args%3A%20any%5B%5D)%20%7B%0D%0A%20%20%20%20super(...args)%3B%0D%0A%20%20%20%20%2F%2F%20sublcass-specific%20code%0D%0A%20%20%7D%0D%0A%0D%0A%7D
Related Issues:
#1790
#11679
The text was updated successfully, but these errors were encountered: