-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Contravariant inference breaks on generic conditional types. #56344
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
Comments
You might consider coming up with an example that doesn't depend on |
@jcalz, not sure if this is what you meant by less problematic, but would this do it? function test<T>(value: T)
{
type I = (
((arg: { a: number }) => void)
| ((arg: { b: number }) => void)
| (T extends number ? (arg: { c: T }) => void : (arg: { c: T }) => void)
) extends ((arg: infer I) => void) ? I : never;
let i : I = null as any;
i.a = 1; // With c defined, i.a is available only up to version 4.1.5. Afterwards, it breaks.
i.b = 1; // Same for i.b.
i.c = value;
} |
I imagine the type should have some obvious real-world utility for a use case the TS team is interested in supporting, but I can't say what that is on first glance. 🤷♂️ |
@jcalz, well, that kinda pulls type Remap<T> = {
[K in keyof T]: T[K] extends number
? { [P in K]: T[K] }
: { [P in K]: T[K] }
}[keyof T]; |
I’m confused why you’re writing Although in the case of |
@fatcerberus, In its extends clause, I'm not looking for enabling the distributive behaviour, but to show that the types I'm having problems with are doing some |
This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Uh oh!
There was an error while loading. Please reload this page.
🔎 Search Terms
mapped types templates contravariant inference
🕗 Version & Regression Information
⏯ Playground Link
https://tsplay.dev/NVrBBN
💻 Code
🙁 Actual behavior
The non-generic dependent properties were not available.
🙂 Expected behavior
At least the non-generic dependent properties to be available. Ideally,
c
should have been available too andvalue
should have been assignable to it, but that's less "expected" than the first part.Additional information about the issue
It completely breaks more complex mapped types that used to work up to 4.1.5. The conditional generic type was still not available, but it was better than nothing.
If the previous behaviour cannot be restored, perhaps there's a way to detect that you're dealing with a generic type which will be deferred, and allow the programmer to decide what to do with it?
The text was updated successfully, but these errors were encountered: