Javascript Array incompatible with ArrayLike

Hello,

I'm trying to write a function that works with any type that can be indexed with a numeric key and has a length property. I know that Typescript defines an interface ArrayLike, which states precisely what I need, so I wrote a function with a similar signature to the following:

/**

@template T

@param {ArrayLike<T>} arr

*/

function func(arr) {}

 

Calling the function with an array value gives me a type mismatch:



However, if I call the function with a NodeListOf value, IDEA doesn't complain:

 

Is there any reason why Array won't match ArrayLike?

Please sign in to leave a comment.