-
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
Undesirable type argument inference from return position #20681
Comments
Looks like this is a potential duplicate of #19682 (and was fixed in the signature of |
Yes: declare function f<T, U = T>(xs: T[], g?: (x: T) => U): U[];
const ns: number[] = f([true]) //should error here: 'boolean' is not assignable to 'number' The rules for defaults may specify that inference works this way currently, but I believe we decided change those rules in a recent design meeting. |
This was reported a few times as a bug in one of TSLint's rules lately. Ref: palantir/tslint#3540 and duplicates Would be awesome if this get's fixed. |
Spoke to @RyanCavanaugh, seems reasonable to say that this should really be two overloads, but it is still pretty undesirable. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
Today, this code type checks because
Array.from<T, U>
takes an optionalmapfn
of type(el: T, index: number) => U
.When
U
is not inferred from themapfn
, it is instead inferred from the contextual type.The text was updated successfully, but these errors were encountered: