Skip to main content
Module

x/scaffold/src/deps/types.ts>ReadonlyDeep

scaffold your next project with style and 💗
Latest
type alias ReadonlyDeep
import { type ReadonlyDeep } from "https://deno.land/x/scaffold@0.3.0/src/deps/types.ts";

Convert objects, Maps, Sets, and Arrays and all of their keys/elements into immutable structures recursively.

This is useful when a deeply nested structure needs to be exposed as completely immutable, for example, an imported JSON module or when receiving an API response that is passed around.

Please upvote this issue if you want to have this type as a built-in in TypeScript.

Examples

Example 1

// data.json
{
	"foo": ["bar"]
}

// main.ts
import type {ReadonlyDeep} from 'type-fest';
import dataJson = require('./data.json.d.ts');

const data: ReadonlyDeep<typeof dataJson> = dataJson;

export default data;

// test.ts
import data from './main';

data.foo.push('bar');
//=> error TS2339: Property 'push' does not exist on type 'readonly string[]'
definition: T extends BuiltIns ? T : T extends (...arguments: any[]) => unknown ? { } extends ReadonlyObjectDeep<T> ? T : HasMultipleCallSignatures<T> extends true ? T : ((...arguments: Parameters<T>) => ReturnType<T>) & ReadonlyObjectDeep<T> : T extends Readonly<ReadonlyMap<infer KeyType, infer ValueType>> ? ReadonlyMapDeep<KeyType, ValueType> : T extends Readonly<ReadonlySet<infer ItemType>> ? ReadonlySetDeep<ItemType> : T extends object ? ReadonlyObjectDeep<T> : unknown