microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.38k stars 12.4k forks source link

Cannot use Array.prototype.push.apply with NodeList, even though it works properly in all browsers. #39312

Open DerGernTod opened 4 years ago

DerGernTod commented 4 years ago

TypeScript Version: 3.9.x-dev.20200627

Search Terms: strictBindCallApply NodeList

Code

const bodyChildren = document.body.childNodes;
const arr: Node[] = [];
arr.push.apply(arr, bodyChildren);

Expected behavior: Doesn't throw errors.

Actual behavior: Throws errors on line 3: Argument of type 'NodeListOf' is not assignable to parameter of type 'Node[]'. Type 'NodeListOf' is missing the following properties from type 'Node[]': pop, push, concat, join, and 19 more.

Playground Link: Playground Link

Related Issues: Couldn't find any.

MartinJohns commented 4 years ago

Possibly related: #36554