-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueHelp WantedYou can do thisYou can do this
Milestone
Description
TypeScript Version: 2.6.2
Code
function takeN<T> (n: number, input: Iterable<T>|ArrayLike<T>): [T[], T[]] {
const array = Array.from(input)
return [array.splice(0, n), array]
}
function takeNv2<T> (n: number, input: Iterable<T>|ArrayLike<T>): [T[], T[]] {
const array = isIterable(input) ? Array.from(input) : Array.from(input)
return [array.splice(0, n), array]
function isIterable(arg: any): arg is Iterable<any> {
return Symbol.iterator in arg
}
}
Expected behavior:
takeN
to work
Actual behavior:
takeN
raises an error on Array.from
, because TypeScript does not accept that the input matches more than one overload.
This is either a compiler bug, or the declaration for Array.from
needs an overload that accepts either.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueHelp WantedYou can do thisYou can do this