Dev Helpers
← Back

Append to a readonly list

Append to a readonly list using TypeScript.

Open this example in the interactive library

Source code

type Item = Readonly<{ id: number; label: string }>;
const items: readonly Item[] = [
  { id: 1, label: "one" },
  { id: 2, label: "two" },
];
console.log([...items, { id: 3, label: "three" } satisfies Item]);

Sample output

[
  { id: 1, label: 'one' },
  { id: 2, label: 'two' },
  { id: 3, label: 'three' }
]