Repository navigation
Casting U|T to U is newly an error in nightly (4.8.0-dev.20220609) #49457
Description
Activity
U | Tis related toU, butXmight not be. For example ifUandTare completely disjoint types andXisT, casting it toUwould almost certainly be a mistake. In fact, that's the exact possibility the error message is hinting at.RyanCavanaugh commented
on Jun 9, 2022 MemberMore actionsThis wasn't an intentional change AFAIK
I mean, the error message is technically true though. 🤷♂️
TypeScript Bot (@typescript-bot) bisect good v4.7.2 bad main
We'll see what the bisect says, but I'm pretty sure this is caused by #48861.
Wesley Wigham (@weswigham) Thoughts?
It is indeed caused by #48861. The code in that PR disallows relating type parameters unless one extends the other in a direct chain. In other words, it doesn't make provisions for union type constraints.
Yup. We could expand it, but as noted by the poster above, it's definitely not a particularly safe cast; it's neither a downcast nor an upcast.
My argument is that
U|Tis enough of a relation toUthat an explicit cast is enough.it's definitely not a particularly safe cast
That is true, though. I could understand a decision either way.
My argument is that U|T is enough of a relation to U that an explicit cast is enough.
See my post above. imo, whether
U | Tis related toUis a red herring, becauseXis generic. The better question is, is the type bound toXalways related to the one bound toU, and the answer is "not necessarily".I'm going to close this as working as intended.
- addedWorking as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bugand removedBugA bug in TypeScriptA bug in TypeScript
on Dec 8, 2022 - locked as resolved and limited conversation to collaborators
on Oct 22, 2025
Bug Report
🔎 Search Terms
TS2352, sufficiently overlaps
🕗 Version & Regression Information
⏯ Playground Link
Playground link (4.7.2) with relevant code (no error)
Playground link (nightly) with relevant code showing the error
💻 Code
🙁 Actual behavior
This is an error in nightly (4.8.0) but was fine in 4.7.2.
🙂 Expected behavior
The new error doesn't feel helpful to me. I expect assigning
U|TtoUto be an error. But the explicit cast feels enough to me becauseU|Tseem related toU. I don't feel like casting throughunknownshould be necessary.