Skip to content
Advertisement

TypeScript: concat arrays with different element-types

This is working.

JavaScript

The fine result is

JavaScript

But what I need is this – and thats not working.

JavaScript

Error:

JavaScript

It works if I make the numbers in tail to strings – what I can not do because of reasons.

So how can I make it work??

Thanks!

Advertisement

Answer

You can declare the type of head like this:

JavaScript

This will remove the error and keep the type-safety in place.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement