// Immutable types borrowed from ts-essentials: https://github.com/ts-essentials/ts-essentials // https://github.com/ts-essentials/ts-essentials/blob/master/lib/deep-readonly/README.md /** The MIT License Copyright (c) 2018-2019 Chris Kaczor (github.com/krzkaczor) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ // eslint-disable-next-line no-restricted-syntax export type Primitive = string | number | boolean | bigint | symbol | undefined | null; // eslint-disable-next-line @typescript-eslint/no-explicit-any export type AnyArray = Array | ReadonlyArray; // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type export type Builtin = Primitive | Function | Date | Error | RegExp; // eslint-disable-next-line @typescript-eslint/no-explicit-any export type IsTuple = Type extends readonly any[] ? // eslint-disable-next-line @typescript-eslint/no-explicit-any any[] extends Type ? never : Type : never; export type IsUnknown = IsAny extends true ? false : unknown extends Type ? true : false; // https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360 export type IsAny = 0 extends 1 & Type ? true : false; export type Immutable = Type extends Exclude ? Type : Type extends Map ? ReadonlyMap, Immutable> : Type extends ReadonlyMap ? ReadonlyMap, Immutable> : Type extends WeakMap ? WeakMap, Immutable> : Type extends Set ? ReadonlySet> : Type extends ReadonlySet ? ReadonlySet> : Type extends WeakSet ? WeakSet> : Type extends Promise ? Promise> : Type extends AnyArray ? Type extends IsTuple ? { readonly [Key in keyof Type]: Immutable } : ReadonlyArray> : // eslint-disable-next-line @typescript-eslint/no-empty-object-type Type extends {} ? { readonly [Key in keyof Type]: Immutable } : IsUnknown extends true ? unknown : Readonly;