-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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 not working with extends
generic argument and keyof
and --strictNullChecks
#13922
Comments
This issue is still present in version 2.2.1-insiders.20170217 |
Running into something similar (i think), on // some complex generic union type alias
type ArrayOrValue<T> = Array<T> | T;
// sample function to consume the complex type above
function foo1<T>(x: ArrayOrValue<T>) {
return x;
}
// some nullable input
let bar: string | undefined;
// bar being inferred as string instead of string | undefined
foo1(bar);
// but there is no problem if the generic typing is explicit
foo1<string | undefined>(bar);
// simpler version of foo1
function foo2<T>(x: T) {
return x;
}
// these calls have no problem with type inference
foo2(bar);
foo2<string | undefined>(bar); |
@ahejlsberg looks like this is one case that was not handled by #15576. any thoughts on this? |
The problem here is |
Turns out this issue has been fixed since 4.3. |
The title of the bug should probably be improved - I was not able to come up with something that encapsulates the issue.
TypeScript Version: 2.1.5, compiling using
--strictNullChecks
This issue seems not to be present in the TypeScript playground (2.1.4-insiders.20161201):
Code
Expected behavior:
All three method calls should compile correctly.
Actual behavior:
The text was updated successfully, but these errors were encountered: