Skip to content

Incorrectly inferred type for union types #43962

Description

Bug Report

🔎 Search Terms

infer, never, union types, error TS2345

🕗 Version & Regression Information

  • This changed between versions 3.5.1 and all newer versions up to 4.3.0-beta. 3.5.1 doesn't throw such error, there is the error in 3.6.2

⏯ Playground Link

Playground link with relevant code

💻 Code

typeThing<T>={value: T;pipe<A,B,C>(opA: Op<T,A>,opB: Op<A,B>,opC: Op<B,C>): Thing<C>;};typeOp<I,O>=(thing: Thing<I>)=>Thing<O>;declarefunctioncreateThing<T>(result: T): Thing<T>;declarefunctionmap<T,R>(project: (value: T)=>R): Op<T,R>;declarefunctiontap<T>(next: (value: T)=>void): Op<T,T>;interfaceWrapped<V>{data: V;props?: object;}declarefunctionisWrapped<T>(obj: any): obj is Wrapped<T>;declarefunctionunwrap<T>(obj: T|Wrapped<T>): T;typeWrappedInferredData<T>=TextendsWrapped<infer R> ? R : T;typeWrappedInput<V>=()=>Thing<V>;declarefunctionaddSettings<V>(data: V|Wrapped<V>,props: object): Wrapped<WrappedInferredData<V|Wrapped<V>>>;constfunctionWithTypingIssue=<V>(factory: WrappedInput<V|Wrapped<V>>): Thing<V>=>{returnfactory().pipe(map((item)=>unwrap(item)),map(item=>item),map(item=>unwrap(item)));}constthisIsTargetValue=1;consta$=functionWithTypingIssue(()=>{constthing=createThing(thisIsTargetValue);returnthing.pipe(map((data)=>addSettings(data,{anyProp: 1})),map((data)=>data),// error heretap((v)=>v));});a$.value;// should be of type thisIsTargetValue
Argument of type 'Op<Wrapped<number>, Wrapped<number>>' is not assignable to parameter of type 'Op<Wrapped<number>, Wrapped<never>>'.
Type 'Wrapped<number>' is not assignable to type 'Wrapped<never>'.
Type 'number' is not assignable to type 'never'. 

🙁 Actual behavior

Type incorrectly infers from union type

🙂 Expected behavior

Type should be resolved correctly. typeof thisIsTargetValue === number for this example

Metadata

Metadata

Labels

Fix AvailableA PR has been opened for this issueNeeds InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions