Repository navigation
3.4.0-rc - behaviour changed from 3.3 (regression?) #30489
Description
Activity
- changed the title
[-]3.4 - behaviour changed from 3.3 (regression?)[/-][+]3.4.0-rc - behaviour changed from 3.3 (regression?)[/+]on Mar 19, 2019 jack-williams commented
on Mar 19, 2019 CollaboratorMore actionsThis is caused by #29437 I think. Not sure I would class this as a regression: is it causing negative behaviour?
At least for me :) , I use it like this
type ExtendIfI1<T> = T extends I1<any> ? T & Something : T
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
type A<T> = T extends any ? T : never type B = A<number> // this is any & number, which is number type O<T> = T extends I<any> ? T : never type B = O<I<number>> // could this be changed so it generates I<any & number>, which is I<number> // rather than I<any> & I<number> ?
RyanCavanaugh commented
on Mar 19, 2019 MemberMore actionsThis 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
type O<T> = T extends I<unknown> ? T : never
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
type O<T> = [T] extends [I<unknown>] ? T : never
- addedWorking as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
on Mar 19, 2019 typescript-bot commented
on Mar 22, 2019 ContributorMore actionsThis issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
- addedExperience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsand removedWorking as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
on 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.Reacted by Javier Gonzalez- addedSuggestionAn idea for TypeScriptAn idea for TypeScript
on Mar 26, 2019
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