import { type Primitive } from './Primitive.js'; /** * Same as built-in `Readonly`, but works recursively: * * ```TypeScript * import { DeepReadonly } from '@ori/ts-utils'; * * const rawData = { * foo: ['bar'], * }; * * const data: DeepReadonly = rawData; * * data.foo.push('bar'); // error TS2339: Property 'push' does not exist on type 'readonly string[]' * ``` * * @typeParam T Base for the new type */ export type DeepReadonly = T extends Primitive | ((...args: any[]) => unknown) ? T : T extends ReadonlyMap ? DeepReadonlyMap : T extends ReadonlySet ? DeepReadonlySet : T extends object ? DeepReadonlyObject : unknown; /** * Helper type for {@link DeepReadonly}. */ type DeepReadonlyMap = ReadonlyMap, DeepReadonly>; /** * Helper type for {@link DeepReadonly}. */ type DeepReadonlySet = ReadonlySet>; /** * Helper type for {@link DeepReadonly}. */ type DeepReadonlyObject = { readonly [K in keyof O]: DeepReadonly; }; export {};