Skip to content
Advertisement

How to declare item types of a zipped list in typescript?

I have two lists like these:

JavaScript

and combined them using zip:

JavaScript

Then, I want to apply a map on the zip like this, for example:

JavaScript

The ‘item’ in the code above implicitly has an ‘any’ type, so I want to define the type like:

JavaScript

but this doesn’t work. Does anyone know how to define the type, for a case like this? I can solve the error, by simply write it as item: any[], but I don’t want to use ‘any’ in my code.

Advertisement

Answer

Your “imaginary syntax” is very close to the real syntax: [object, number], and for an array of these arrays, [object, number][].

JavaScript

TypeScipt Playground

Advertisement