/** * Immutable is a utility type that will make the given array/map/set/object recursively read-only. * * You can use this type to easily build safe data structures. * * From: https://stackoverflow.com/questions/41879327/deepreadonly-object-typescript */ export type Immutable = T extends ImmutablePrimitive ? T : T extends Array ? ImmutableArray : T extends Map ? ImmutableMap : T extends Set ? ImmutableSet : ImmutableObject; type ImmutablePrimitive = | boolean | number | string | Function // eslint-disable-line @typescript-eslint/no-unsafe-function-type | null | undefined; type ImmutableArray = ReadonlyArray>; type ImmutableMap = ReadonlyMap, Immutable>; type ImmutableSet = ReadonlySet>; type ImmutableObject = { readonly [K in keyof T]: Immutable };