How to use typed arrays with TypeScript?

Sometimes, we want to use typed arrays with TypeScript.

In this article, we’ll look at how to use typed arrays with TypeScript.

How to use typed arrays with TypeScript?

To use typed arrays with TypeScript, we can use the Array type.

For instance, we write

const possessions: Array<Thing> = new Array<Thing>();

to create the possessions variable of type Array<Thing>, which means all entries in the possessions array must be of type Thing.

We can also shorten it to

const possessions: Thing[] = [];

Conclusion

To use typed arrays with TypeScript, we can use the Array type.