TypeScript readonly
readonly prevents assignment through a particular typed reference. It helps communicate borrowing and snapshot intent, but it does not freeze the underlying JavaScript object.
How it works
A public summary should not let a display function change the stock record it reads. The example creates a copied object and exposes it as Readonly<Lot>. Copying and readonly solve different problems: the copy separates these top-level values, while the type restricts writes through the snapshot reference. Nested objects would still need their own ownership decision.
Run the code
Try in playground loads this source without running it. Choose Run when ready. The existing TypeScript 5.8.3 worker transpiles and executes one file; it does not perform full semantic type checking, load npm imports or provide DOM/Node APIs. Use the local compiler for the type contract.
For a full check, save the three downloads together in a new folder, run npm install, then npm run check. Use npm run build followed by npm start to execute the checked JavaScript with Node. The supplied project enables strict checking, indexed-access checks and exact optional properties.
Example
type Lot = { code: string; packets: number };
const stored: Lot = { code: "RD-2", packets: 6 };
const snapshot: Readonly<Lot> = { ...stored };
stored.packets = 4;
console.log(snapshot.packets, stored.packets);
Expected result
6 4
The snapshot keeps six because the code copied primitive fields before changing stored. A readonly alias to the original object would observe its later change. Use Object.freeze only when its shallow runtime restriction fits the application; do not describe either mechanism as automatic deep immutability.