Readonly inputs make accidental mutation a type error. A nonmutating reverse creates a new order while preserving the caller's original sequence.
Worked example
type Item = Readonly<{ id: number; label: string }>;
const items: readonly Item[] = [
{ id: 1, label: "one" },
{ id: 2, label: "two" },
];
console.log(items.toReversed());Result
[ { id: 2, label: 'two' }, { id: 1, label: 'one' } ]Implementation notes
Readonly is shallow unless the nested values are readonly as well. A new array order does not copy the records it contains.
Try it yourself
Keep a reference to the original array and compare it after the call.
Open the TypeScript example →Editorial date August 24, 2025 · Published December 6, 2026