TypeScript Types
Array types — homogeneous element contracts
An array type specifies the permitted element type, not a fixed length. Mutable arrays expose methods such as push, and those calls are checked against the element type. The compiler does not guarantee an index exists: the noUncheckedIndexedAccess option can add undefined to unchecked indexed reads. For fixed positional contracts, prefer a tuple. Example output: "2,4,6". The example was designed for strict checking with an ES2022 target; type annotations do not add runtime validation.
Formal Syntax & Structure
typescript syntaxtypescript
let values: T[]; // or Array<T>Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| T | type | Permitted array element type. |
Working Example
Example Snippettypescript
const values: number[] = [2, 4];values.push(6);console.log(values.join(","));