RecipesChapter 3: The Type System

Pinning Types with Const Context

Recipe 3.4 from The TypeScript Cookbook

const circle = {
  radius: 2,
  kind: "circle",
} as const;

area2(circle); // Works!

circle.kind = "rectangle";
//     ^-- Cannot assign to 'kind' because 
//         it is a read-only property.
Open in TypeScript Playground →