Skip to content

Strict function check failure due to union type with matching parameters in the unioned interfaces #20714

Closed
@liminf

Description

@liminf

TypeScript Version: 2.7.0-dev.20171214

Code

export class Missing {
    public str : string;
}

export type ResultOrMissing<A> = A | Missing;

export interface IBar<A> {
    myParam: ResultOrMissing<A>;
}
export interface IFoo<A> {
    myParam: A;
}

export type BothOrUndefined<A> = (IFoo<A> | IBar<A>);

export interface IReturnsBoth {
    <A>() : (BothOrUndefined<A> | undefined);
}

const helper : IReturnsBoth = <A>() : (BothOrUndefined<A> | undefined) => {
        return undefined;
    };

Expected behavior:
Compiling the above code with "tsc .ts -strictFunctionTypes" should succeed.

Actual behavior:
Somehow wires get crossed and we get this error:

repro.ts(20,7): error TS2322: Type '<A>() => IFoo<A> | IBar<A>' is not assignable to type 'IReturnsBoth'.
  Type 'IFoo<ResultOrMissing<A>> | IBar<ResultOrMissing<A>>' is not assignable to type 'IFoo<A> | IBar<A>'.
    Type 'IBar<ResultOrMissing<A>>' is not assignable to type 'IFoo<A> | IBar<A>'.
      Type 'IBar<ResultOrMissing<A>>' is not assignable to type 'IBar<A>'.
        Type 'ResultOrMissing<A>' is not assignable to type 'A'.
          Type 'Missing' is not assignable to type 'A'.

Note the unexplained switch from IBar<A> to IBar<ResultOrMissing<A>>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions