Skip to content

Function overload do not pick up right case #20032

@honzabrecka

Description

@honzabrecka

TypeScript Version: 2.7.0-dev.201xxxxx

Example 1

Code

interface Dict<T> {
  [key: string]: T
}

declare function filter<T>(fn: (value: T) => boolean): (x: Dict<T>) => Dict<T>;
declare function filter<T>(fn: (value: T) => boolean): (x: T[]) => T[];

declare function pipe<V0, T1>(fn0: (x0: V0) => T1): (x0: V0) => T1;
declare function pipe<V0, T1, T2>(fn0: (x0: V0) => T1, fn1: (x: T1) => T2): (x0: V0) => T2;

const x = pipe(filter((x: string) => true))

console.log(x(['foo']))

Expected behavior:

x is of type (v: string[]) => string[]

Actual behavior:

Argument of type 'string[]' is not assignable to parameter of type 'Dict'.

Example 2

Code

interface Dict<T> {
  [key: string]: T
}

declare function filter<T>(fn: (value: T) => boolean): (x: Dict<T>) => Dict<T>;
declare function filter<T>(fn: (value: T) => boolean): (x: T[]) => T[];

declare function pipe<V0, T1>(fn0: (x0: V0) => T1): (x0: V0) => T1;
declare function pipe<V0, T1, T2>(fn0: (x0: V0) => T1, fn1: (x: T1) => T2): (x0: V0) => T2;

// >>> specialized id, which should specify filter overload
const id = (x: string[]): string[] => x

const x = pipe(id, filter((x: string) => true))

console.log(x(['foo']))

Expected behavior:

x is of type (v: string[]) => string[]

Actual behavior:

Argument of type 'string[]' is not assignable to parameter of type 'Dict'. Now failing on filter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions