Course contentsShow
← TypeScript
Lesson 1760 of 1,79640. The Future of TypeScriptFree lesson

Records and Tuples: Immutable Primitives

The Records & Tuples proposal for deeply immutable data structures and TypeScript typing implications.

Records and Tuples: Immutable Primitives

You'll learn: How the TC39 Records & Tuples proposal brings deeply immutable data structures to JavaScript and what that means for TypeScript's type system.

The Proposal: Immutable Value Types

Records and Tuples are a Stage 2 TC39 proposal that introduces immutable, deeply-compared primitive value types to JavaScript. Think of them as frozen objects and arrays, but at the language level:

// Proposed syntax (not yet available)
const record = #{ x: 1, y: 2 };  // Immutable object-like
const tuple = #[1, 2, 3];        // Immutable array-like

The # prefix marks these as special primitives, not objects.

Why This Matters

Today, objects and arrays are reference types—two identical-looking objects aren't equal:

const obj1 = { x: 1 };
const obj2 = { x: 1 };
obj1 === obj2;  // false (different references)

Records and Tuples would use value equality:

#{ x: 1 } === #{ x: 1 };  // true (same value)
#[1, 2] === #[1, 2];      // true

This makes them perfect for React props, Redux state, and Map/Set keys—no more accidental mutations or reference comparison bugs.

TypeScript's Challenge

TypeScript will need to type these new primitives distinctly from regular objects and arrays. The proposal suggests they can only contain other primitives or Records/Tuples (no nested objects), which TypeScript would enforce at compile time.

Expected type checking:

const validRecord = #{ x: 1, nested: #{ y: 2 } };  // ✓
const invalidRecord = #{ obj: { x: 1 } };          // Error: objects not allowed

TypeScript would also need to prevent mutation attempts and handle the structural equality implications in generic constraints and conditional types.

Key Takeaway: Records and Tuples would give JavaScript true immutable primitives with value equality, requiring TypeScript to add new type-checking rules for deeply immutable, primitive-only data structures—a major shift from today's object/array typing.