Explain the concept of Tuple types in TypeScript.

Instruction: Provide an example and explain how Tuple types are used in TypeScript.

Context: This question assesses the candidate's understanding of Tuple types in TypeScript, including their syntax and practical applications.

Updated

Official answer available

Read the opening below, then unlock the full answer and practical guidance.

A tuple is an array type whose positions have specific meanings and types. A simple tuple has a known length; optional and rest elements can describe variable-length forms. Tuple annotations do not create a special runtime container.

``typescript type Reading = readonly [label: string, value: number]; function formatReading([label, value]: Reading): string { return${label}: ${value.toFixed(1)}`; } const reading: Reading = ["temperature",...

Related Questions