On this page
  1. readonly
  2. Syntax & Overview
  3. Notes & Pitfalls
  4. Example

readonly

Prev: `as const` | Up: builtins | Next: `is`
Rel: builtins, Structural Typing & Narrowing
Ref: TypeScript Docs — readonly
Tags: #public #web #typescript #builtins #tier/core


Syntax & Overview

interface Point { readonly x: number; readonly y: number; }

Prevents compile-time reassignment of properties, array elements (readonly T[]), or tuples (readonly [number, number]).

Notes & Pitfalls

Example

interface Config {
  readonly host: string;
  readonly ports: readonly number[];
}

const cfg: Config = { host: "localhost", ports: [80, 443] };
// cfg.ports.push(8080); // compile-time error

Linked from

Related notes