Skip to content

Incorrect overload selected for Array.prototype.map(...) #47571

Description

@oleg-slapdash

Bug Report

🔎 Search Terms

overload, array.prototype.map

🕗 Version & Regression Information

  • This is the behavior in every version I tried.

⏯ Playground Link

Playground link with relevant code

💻 Code

declaretypeObj={a: true};declareconstarr: Array<string|Obj>;declarefunctionfunc(url: string|Obj): string;declarefunctionfunc<TextendsObj|string>(url: T): string|null;constfails: string[]=arr.map(func);// ^^^ Type '(string | null)[]' is not assignable to type 'string[]'.constworks: string[]=arr.map((v)=>func(v));interfaceCustomArray<T>{map<U>(callbackfn: (value: T)=>U): U[];}declareconstarr2: CustomArray<string|Obj>;constfails2: string[]=arr2.map(func);// ^^^ Type '(string | null)[]' is not assignable to type 'string[]'.constworks2: string[]=arr2.map((v)=>func(v));

🙁 Actual behavior

It fails to select the correct overloard.

🙂 Expected behavior

It is supposed to select the correct overload.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions