You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[5.4 regression] Conditional type changes behavior with 5.4-beta #57221
I can confirm that inferToMappedType is now able to infer more because the constraintType that it receives is a type parameter (T) and not an intersection like before (T & string). The mentioned intersection was reduced to just T as per #56515 so I think this is working as intended.
The NoInfer looks like a good workaround to this issue because that's precisely what it is useful for - it limits the inference sources and #56515 made the second argument a viable inference source here.
I feel like this is the same problem that breaks the inference in MikroORM for the populate hints (and many other things that work on the same basis), it starts to break with 5.4.0-dev.20231121, previously I was able to infer string literals and now I only get string which breaks other types. I'll try to work on a playground when I have some spare time and open a separate issue, but the types are pretty complex so it might take some time.
If this is considered WAI, I am honestly scared... 🤣 The use case on our end is more complex than just validation, we need inference so the types can be used in the return values.
Will work on the repro and open a new issue soon'ish, just wanted to bring this up, as I feel a storm is coming (already got a report about this some time ago).
Activity
Andarist commentedon Jan 29, 2024
bisected to #56515
Andarist commentedon Jan 29, 2024
I can confirm that
inferToMappedTypeis now able to infer more because theconstraintTypethat it receives is a type parameter (T) and not an intersection like before (T & string). The mentioned intersection was reduced to justTas per #56515 so I think this is working as intended.The
NoInferlooks like a good workaround to this issue because that's precisely what it is useful for - it limits the inference sources and #56515 made the second argument a viable inference source here.B4nan commentedon Jan 31, 2024
I feel like this is the same problem that breaks the inference in MikroORM for the populate hints (and many other things that work on the same basis), it starts to break with
5.4.0-dev.20231121, previously I was able to infer string literals and now I only getstringwhich breaks other types. I'll try to work on a playground when I have some spare time and open a separate issue, but the types are pretty complex so it might take some time.If this is considered WAI, I am honestly scared... 🤣 The use case on our end is more complex than just validation, we need inference so the types can be used in the return values.
Will work on the repro and open a new issue soon'ish, just wanted to bring this up, as I feel a storm is coming (already got a report about this some time ago).
edit: solved via mikro-orm/mikro-orm#5197
RyanCavanaugh commentedon Feb 1, 2024
The difference here is in the type parameter inference. In 5.4 we get
whereas in 5.3 it's only
Generic inference has always been willing, in other cases, to produce a string literal union:
so it's at least somewhat apparent that the 5.3 behavior is the incorrect (or at least inconsistent) one.
typescript-bot commentedon Feb 4, 2024
This issue has been marked as "Not a Defect" and has seen no recent activity. It has been automatically closed for house-keeping purposes.