-
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
Type inference for union type passed to overloaded generic function seems broken #20215
Comments
looking at the spec, seems like PRs welcomed. we should also combine the existing overloads to be: new(value: number | string | Date): Date; |
Hey @mhegazy, thanks for checking into this. You are correct, Let me know where I can provide more details! Thanks again. |
Unions are not distributed over calls at the moment. in other words, |
I think that's the heart of the issue. I'm happy to change the |
Please see #14107 |
We should combine the two |
Setting interface DateConstructor {
new (value: number | string | Date): Date;
} Comparing the ES5 and ES6/ES2015 specs, the latter is where |
TypeScript Version: 2.7.0-dev.20171121, 2.6.1
Type unions coming specifically from an interface and passed to an overloaded generic constructor (like
new Date
) seems to break the type inference. Neither of the possible constructor overloads are matched, even though both parts of the type union are supported by the constructor.Code
Expected behavior:
target => 2017-11-22T04:08:13.477Z
Actual behavior:
Argument of type 'string | Date' is not assignable to parameter of type 'VarDate'. Type 'Date' is not assignable to type 'VarDate'.
The text was updated successfully, but these errors were encountered: