Open orange4glace opened 2 years ago
i think it should be const g_with_t: G<T> = t;
?
because G<XY>
isn't the same as G<T>
, which can be narrower
because
G<XY>
isn't the same asG<T>
, which can be narrower
I think G<T>
to G<XY>
is broadening 🤔
Is there any case that G<T>
to G<XY>
is narrowing?
yeah, looking at this again, i think it should be possible to widen the constrained T
back to XY
i kinda read your example like this, which isn't the same
function func<T extends XY>(): G<T> {
return {} as G<XY>; // slightly different TS2322
}
Bug Report
I am not sure this is intentional or not.
🔎 Search Terms
TS2322 generic union
🕗 Version & Regression Information
4.5.4
⏯ Playground Link
https://www.typescriptlang.org/play?#code/C4TwDgpgBAGlC8UDeUAeAuKA7ArgWwCMIAnAbigF8AoUSKATQWShE10JPOtuhkcTgAfBqSo1w0AOIAeACpQIqYBCwATAM6x6APiZIqUKAHM2+ImSoUoAMiizRVAGY4sAY2ABLAPZYozt3IKSioaWtoAFACUzFAGUK4+6sBomPqGhiZQAAxxVrYwooYJWElorMhxGZg5hnlQ4UIMkYXxicnAqZXG1bk2dg5FbcYA+gDuHsAAFsMYUDJ8uoioLQD0K1AA8gDSccWlRmMT06jl8zpMJ6vr27tDB+NTwx1z0gtMwFd2AMoATADMPx+liAA
💻 Code
🙁 Actual behavior
TS2322 occurs
🙂 Expected behavior
It should not, maybe?