Declare the element type when you initialize the array: const names: string[] = [];. This creates an empty array intended to hold strings. You can write the same type as Array<string>.
Create an empty string array
Use a type annotation to make the array’s intended element type explicit:
const names: string[] = [];
TypeScript also supports the generic form:
const otherNames: Array<string> = [];
Both string[] and Array<string> are documented ways to write an array type in TypeScript. TypeScript Handbook: Arrays
Add strings and use the array
Once declared as string[], the array can be populated with strings and used like other mutable arrays:
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errors#1 Best Overall
const tags: string[] = [];
tags.push("typescript");
tags.push("arrays");
for (const tag of tags) {
console.log(tag);
}
console.log(tags.length); // 2
Methods such as push add elements; length reports the current number of elements.
Why annotate an array initialized with []?
An empty literal contains no example elements from which TypeScript can determine the intended element type. Inference also depends on context and compiler settings, so do not assume every bare [] receives the same type in every situation. An explicit annotation states the intent where the array is declared.
Rank #2
- TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
- TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
- Lightweight, Classic fit, Double-needle sleeve and bottom hem
The TypeScript documentation specifically notes that an empty array initializer in a checked JavaScript (.js) file is treated as any[]. TypeScript’s implicit-any documentation describes errors for particular contexts; these examples do not establish one universal inference outcome for all TypeScript versions and configurations. See TypeScript: Type Inference and TypeScript 2.1 Release Notes.
Choose a notation and the right nullability
string[] is concise, while Array<string> makes the generic container form visible. They express the same element type; choose the form that fits the conventions in your codebase.
If an element may be absent or null, express that requirement in the type rather than leaving the empty array untyped. For example, with strict null checking enabled, string | undefined is distinct from string. TypeScript’s Handbook recommends enabling strictness checks for new codebases where possible: TypeScript Handbook: Basic Types.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




