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
3.4.0-rc - behaviour changed from 3.3 (regression?) #30489
I found a case where types yielded differ between 3.3 and 3.4, but I'm not sure if it is a regression or it is intended
interfaceI<T>{a: T}// this is different between 3.3 and 3.4typeO<T>=TextendsI<any> ? T : nevertypeB=O<I<number>>// I<number> in TS3.3, I<any> & I<number> in TS3.4 (which boils down to I<any>// this however is the sametypeO2<T>=TextendsI<infer _> ? T : nevertypeB2=O2<I<number>>// I<number> in both
typeExtendIfI1<T>=TextendsI1<any> ? T&Something : T
I can't use T extends I1<infer X> ? I1<X> & Something : T since if I1 had more stuff than I1 it would be lost, and having to write infer on the left for it to work was hard to find out
I think it boils down to the generic being inside the template part, this is
typeA<T>=Textendsany ? T : nevertypeB=A<number>// this is any & number, which is numbertypeO<T>=TextendsI<any> ? T : nevertypeB=O<I<number>>// could this be changed so it generates I<any & number>, which is I<number>// rather than I<any> & I<number> ?
While the original behavior was intended, its interaction with any is undesirable - to reduce breakage and make better output types, in #30592 we introduce supertype reduction on substitution type instantiation, which should eliminate needless any'd up intersection members in most cases.
Activity
[-]3.4 - behaviour changed from 3.3 (regression?)[/-][+]3.4.0-rc - behaviour changed from 3.3 (regression?)[/+]jack-williams commentedon Mar 19, 2019
This is caused by #29437 I think. Not sure I would class this as a regression: is it causing negative behaviour?
xaviergonz commentedon Mar 19, 2019
At least for me :) , I use it like this
I can't use
T extends I1<infer X> ? I1<X> & Something : Tsince if I1 had more stuff than I1 it would be lost, and having to write infer on the left for it to work was hard to find outI think it boils down to the generic being inside the template part, this is
RyanCavanaugh commentedon Mar 19, 2019
This is the intended behavior to improve inference elsewhere by "collapsing" conditional types into plain types when we detect that's possible.
One option is to use
This will produce the type
I<unknown> & I<number>which is indistinguishable fromI<number>but also a little ugly.You can also make the conditional non-distributive by writing
typescript-bot commentedon Mar 22, 2019
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
weswigham commentedon Mar 26, 2019
While the original behavior was intended, its interaction with
anyis undesirable - to reduce breakage and make better output types, in #30592 we introduce supertype reduction on substitution type instantiation, which should eliminate needlessany'd up intersection members in most cases.