-
Notifications
You must be signed in to change notification settings - Fork 12.8k
When calculating inferred infer type constraints, replace conditionals… #48648
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
When calculating inferred infer type constraints, replace conditionals… #48648
Conversation
…s within mapped type templates with their constraints
// well enough (or at all, from what I've seen - it only filters out parameters which are unreferenced _everywhere_, | ||
// rather than those which are unused within the given node). | ||
// | ||
// Each of those relationship issues, in turn, then cause inference of the `infer` type parameter in question to fail. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment block is informative for whomever comes back to this in the future - I looked at two other ways to solve the problem (the conditional in the template type executing differently than the mapped type around it would imply when instantiated in the above fashion), but both ran against other issues in the checker. If one of the other's root issues get fixed, I think they'd be much more elegant constructions to return here than this conditional-constraint-walking logic (ideally the first of the two, since it much more closely matches the structure traversed).
@@ -9,7 +9,7 @@ type KeysWithoutStringIndex<T> = | |||
|
|||
// Only "foo" | "bar" as expected, [string] index signature removed | |||
type test = KeysWithoutStringIndex<{ [index: string]: string; foo: string; bar: 'baz' }> | |||
>test : never | |||
>test : "foo" | "bar" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fun fact - this test already showed the issue, we just weren't looking for it in this test. (Instead we were looking for a constraint error on a different line.)
I'm somewhat puzzled by the logic that attempts to add constraints to |
@ahejlsberg i stumbled upon this one while looking into something else - removing the code from #43649 indeed fixes the expected type result (as this PR does, from
|
There are currently (at least) 3 issues open related to this: #46020 #44143 #44351 All of them would get fixed if #43649 would get reverted (as in, that PR broke them). "Known keys" would get fixed in all of them if this PR here would get merged but the third issue also suffers from index access error and that is not fixed by this PR here. Note for other reviewers: the main problem here is that |
@weswigham This has been open for a couple of years. If this isn't the right solution, should we close it? Either way, this fix is probably minor enough to wait until Corsa has overtaken Strada. |
…within mapped type templates with their constraints.
Fixes #44143