Closed
Description
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
declare type Obj = {a: true};
declare const arr: Array<string | Obj>;
declare function func(url: string | Obj): string;
declare function func<T extends Obj | string>(url: T): string | null;
const fails: string[] = arr.map(func);
// ^^^ Type '(string | null)[]' is not assignable to type 'string[]'.
const works: string[] = arr.map((v) => func(v));
interface CustomArray<T> {
map<U>(callbackfn: (value: T) => U): U[];
}
declare const arr2: CustomArray<string | Obj>;
const fails2: string[] = arr2.map(func);
// ^^^ Type '(string | null)[]' is not assignable to type 'string[]'.
const works2: 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.