Skip to content

Wrong overload resolution with generics #11343

@aikoven

Description

@aikoven

TypeScript Version: 1.8.10

Code

declare function compose<A, B, R>(f1: (b: B) => R, f2: (a: A) => B): (a: A) => R;

declare function compose<R>(...funcs: Function[]): (arg: any) => R;


type Creator<S> = () => S;
type Enhancer = <S>(creator: Creator<S>) => Creator<S>;

declare const enhancer1: Enhancer;
declare const enhancer2: Enhancer;

const enhancer = compose(enhancer1, enhancer2);

const creator = enhancer(() => '');
creator();

Expected behavior:
Should compile with no error.

Actual behavior:
Compiler gives error on the last line:

Uncaught Semantic: Cannot invoke an expression whose type lacks a call signature.

However if we remove the second oveload of compose, everything works fine, which means that the first overload actually matches but for some reason the second one is selected.

Also, if we remove type variable from Enhancer definition and replace it with string, it compiles again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions