TypeScript Syntax and Type Operators
Optional tuple element — variable tuple length
An optional tuple element permits shorter tuples; its read type includes undefined under strict null checking. An ordinary required element cannot follow an optional element in a fixed tuple declaration. The tuple length type can be a union of permitted lengths, unlike a general array length. Optionality is a static contract and does not fill missing positions. Example output: "untitled". Tested in the strict TypeScript 5.8.3 / ES2022 baseline; the example is not a runtime type validator.
Formal Syntax & Structure
typescript syntaxtypescript
type Entry = [id: number, label?: string];Working Example
Example Snippettypescript
type Entry = [id: number, label?: string];const entry: Entry = [7];console.log(entry[1] ?? "untitled");