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.with(0, { id: 1, label: "new" }));
Sample output
[ { id: 1, label: 'new' }, { id: 2, label: 'two' } ]