Categories
TypeScript Answers

How to create a strongly typed array of arrays in TypeScript?

Spread the love

Sometimes, we want to create a strongly typed array of arrays in TypeScript.

In this article, we’ll look at how to create a strongly typed array of arrays in TypeScript.

How to create a strongly typed array of arrays in TypeScript?

To create a strongly typed array of arrays in TypeScript, we can nest the Array type.

For instance, we write

const x: Array<Array<Foo>> = [];

to declare variable x with the nested array entries having the Foo type with Array<Array<Foo>>.

Conclusion

To create a strongly typed array of arrays in TypeScript, we can nest the Array type.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *