-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Don't allow signature overloads for ambient declarations #13785
Copy link
Copy link
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug