
Arrays
In JavaScript array can contain any type of data or mix of data types
Array Type Annotations
The TypeScript type annotation for array types is fairly straightforward: we put [] after the element type. In this code, names is an Array that can only contain strings:
let names: string[] = ['Danny', 'Samntha']
// or you can declare as the following
let names: Array<string> = ['Danny', 'Samantha']
if you try to assign number to names array, you will get a type error
let names: string[] = [1, 2, 3] // Type Error!
names.push(562) // Type Error!
Multi-dimensional Arrays
You can declare multi demensional arrays as:
let myArray: string[][]
Related articles
10 Essential Steps for Migrating Your JavaScript Project to TypeScript in 2025
Discover the practical roadmap to seamlessly transition your JavaScript projects to TypeScript, enhancing type safety and developer productivity in 2025.
Crafting Dynamic Data-Driven User Interfaces with React and TypeScript
Learn how to effortlessly craft dynamic, data-driven user interfaces using React and TypeScript, enhancing your app's responsiveness and user experience.
Mastering Next-Gen API Security: JWTs with Node.js & TypeScript in 2025
Learn step-by-step how to enhance your API’s security using JWTs with Node.js and TypeScript, preparing your applications for the security demands of 2025.