-
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
Mixing tuple & generics #1011
Comments
Technically by design, but the design should probably change. Under discussion. |
We have special logic for inferring to a union type. But I think we need to say that if we are inferring from a union type, certain constituents of the target can "use up" certain constituents of the source. Then the remainder of the source constituents can be inferred to the target's plain type parameter constituent if it exists. |
Sorry it was probably unclear why I was talking about union types. It's because the tuple type is an Array of the union elements. So the tuple type in the parameter is an |
Ok thanks for the explanation ! |
Discussed with @ahejlsberg and we decided that the type argument inference candidates should be stratified. In this case, the thing we are inferring to has the following shape: ... extends Array<string | T> {
0: string;
1: T;
} and the argument has the following shape: ... extends Array<string | boolean> {
0: string;
1: boolean;
} The bug is that we infer two candidates for T, namely boolean (from the 1 property) and string | boolean (from the Array portion of the tuple). The former is a good inference. The latter is not such a good inference, and it comes from trying to infer from string | boolean to string | T. Because it doesn't make a whole lot of sense to infer to a bare type parameter that is part of a union type, we'd like this inference to be secondary to the good inferences. So we shall have primary inferences and secondary inferences. The secondary inferences can be used as a fallback in case the primary inferences are absent or conflicting. But we cannot eliminate these secondary inferences because we need them in order for Promises to be inferred correctly. |
Hi, don't understand why this code doesn't compile:
Someone can help me ?
The text was updated successfully, but these errors were encountered: