-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Array.prototype.map
seems to fail if given a disjoint union of different array types
TypeScript Version: 2.2.2 (also tried 2.3.4. Reproducible on the Playground as well)
Code
function map<T>(items: T[] | string[]) {
items.map(x => x)
}
Also fails:
function map<T>(items: Array<T> | Array<string>) {
items.map(x => x)
}
Expected behavior:
Maybe this should work?
Actual behavior:
Type Error:
Cannot invoke an expression whose type lacks a call signature. Type '{ <U>(this: [string, string, string, string, string], callbackfn: (value: string, index: number, ...' has no compatible call signatures.
Workaround
The following does work:
function map<T extends object | string>(items: T[]) {
items.map(x => x)
}
Perhaps not a bug since a workaround exists - I don't know if the workaround would be a preferred method?
kujon
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created