🔍 Search Terms
issue #14829
pull #56794 (The pull for 14829)
✅ Viability Checklist
⭐ Suggestion
These are conditional type examples in the 2.8 release doc:
typeFoo<T>=Textends{a: infer U;b: infer U} ? U : never;typeT10=Foo<{a: string;b: string}>;// stringtypeT11=Foo<{a: string;b: number}>;// string | numbertypeBar<T>=Textends{a: (x: infer U)=>void;b: (x: infer U)=>void}
? U
: never;typeT20=Bar<{a: (x: string)=>void;b: (x: string)=>void}>;// stringtypeT21=Bar<{a: (x: string)=>void;b: (x: number)=>void}>;// string & numberThe proposal is that the such generic types support NoInfer, for example:
typeFoo<T>=Textends{a: infer U;b: NoInfer<infer U>} ? U : never;typeT10=Foo<{a: string;b: string}>;// stringtypeT11=Foo<{a: string;b: number}>;// (expecting string)typeBar<T>=Textends{a: (x: infer U)=>void;b: (x: NoInfer< infer U>)=>void}
? U
: never;typeT20=Bar<{a: (x: string)=>void;b: (x: string)=>void}>;// stringtypeT21=Bar<{a: (x: string)=>void;b: (x: number)=>void}>;// (expecting string)📃 Motivating Example
Testing the latest dev version with pull #56794, these results were obtained:
typeFoo<T>=Textends{a: infer U;b: NoInfer<infer U>} ? U : never;>Foo : Foo<T>>a : U>b : NoInfer<U>typeT10=Foo<{a: string;b: string}>;// string>T10 : string>a : string>b : stringtypeT11=Foo<{a: string;b: number}>;// never (expecting string)>T11 : never<-WASEXPECTINGSTRING>a : string>b : numbertypeBar<T>=Textends{a: (x: infer U)=>void;b: (x: NoInfer< infer U>)=>void}>Bar : Bar<T>>a : (x: infer U)=>void>x : U>b : (x: NoInfer<infer U>)=>void>x : NoInfer<U>
? U
: never;typeT20=Bar<{a: (x: string)=>void;b: (x: string)=>void}>;// string>T20 : string>a : (x: string)=>void>x : string>b : (x: string)=>void>x : stringtypeT21=Bar<{a: (x: string)=>void;b: (x: number)=>void}>;// (expecting string)>T21 : never<-WASEXPECTINGSTRING>a : (x: string)=>void>x : string>b : (x: number)=>void>x : numberThe location marked with <- WAS EXPECTING STRING show results of never where string was expected.
💻 Use Cases
- What do you want to use this for?
🔍 Search Terms
issue #14829
pull #56794 (The pull for 14829)
✅ Viability Checklist
⭐ Suggestion
These are conditional type examples in the 2.8 release doc:
The proposal is that the such generic types support
NoInfer, for example:📃 Motivating Example
Testing the latest dev version with pull #56794, these results were obtained:
The location marked with <- WAS EXPECTING STRING show results of
neverwherestringwas expected.💻 Use Cases