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

as const

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


Syntax & Overview

const ROLES = ['admin', 'member'] as const;

Marks an object or array literal deeply readonly and narrows values to their exact literal types.

Notes & Pitfalls

Example

const ROLES = ["admin", "editor", "viewer"] as const;
type Role = (typeof ROLES)[number]; // "admin" | "editor" | "viewer"

const role: Role = "editor";

Linked from

Related notes