-
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
inference strangeness - 3 #6037
Comments
Sorry, when you wrote |
I did. Good catch. Fixed. |
Okay, so here's what's happening, cutting to the important parts.
So given the one-at-a-time directionality of each inference process (type argument inference and contextual typing), I'm not sure how this could be modeled appropriately. |
Glad we found a corner case. |
Hey, guess what - thanks to @ahejlsberg's current work on allowing type parameters to extend each other (#5949), you should be able to do this in TypeScript 1.8! You'll just need to write function append<a, b extends a>(values: a[], value: b): a[] {
values.push(value);
return values;
} Here's the full example: let value: [string, string];
value = ['hey', 'nay']; // <-- works, an array literal can be assigned to a tuple
function fold<a, r>(values: a[], result: r, fold: (result: r, value: a) => r): r {
for (let value of values) {
result = fold(result, value);
}
return result;
}
function append<a, b extends a>(values: a[], value: b): a[] {
values.push(value);
return values;
}
fold(
[1, 2, 3],
[] as [string, string][],
(result, value) => append(
result,
['', '']
)
); |
So while I'm marking this as by design, you should have a (more correct) workaround. |
looks like working, the language service in VS doesn't complain about, however I cannot verify 100% because of the will be waiting for that branch to be merged and available in nightly builds thanks! |
Overheard conversation on the street:
The text was updated successfully, but these errors were encountered: