Skip to content

Don't allow signature overloads for ambient declarations #13785

@MrMatthewLayton

Description

@MrMatthewLayton

Spec
According to the MDN specification for Array.prototype.map() map should be used like this...
var new_array = arr.map(callback[, thisArg])

Problem
TypeScript has several overloaded implementations for map, and this makes it very difficult to extend Array<T>.

I would expect to see this (which is in lib.d.ts)...
map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[];

But lib.d.ts also has these...

map<U>(this: [T, T, T, T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U, U, U, U];
map<U>(this: [T, T, T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U, U, U];
map<U>(this: [T, T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U, U];
map<U>(this: [T, T], callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): [U, U];

Objection
Since JavaScript does not allow method overloading, and neither does TypeScript for class implementation, I don't think that TypeScript should allow this for ambient declarations either.

Original Post
http://stackoverflow.com/questions/41959269/typescript-array-prototype-map-declaration

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