rivo
Version:
🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.
32 lines (29 loc) • 850 B
TypeScript
import type { Ary } from ".";
import type { Args, Fn } from "../HKT";
import type { AssertBool } from "../helpers";
/**
* Check if an {@link Ary} (i.e., `Array` or `ReadonlyArray`) is readonly.
*
* Sig: `(a: Ary) => boolean`
*
* @example
* ```typescript
* type R1 = IsReadonly<string[]>;
* // ^?: false
* type R2 = IsReadonly<readonly number[]>;
* // ^?: true
* type R3 = IsReadonly<["foo", "bar"]>;
* // ^?: false
* type R4 = IsReadonly<readonly [42, 1337, ...string[]]>;
* // ^?: true
* ```
*/
export type IsReadonly<A extends Ary> = AssertBool<A extends unknown[] ? false : true>;
/**
* [Fn] Check if an {@link Ary} (i.e., `Array` or `ReadonlyArray`) is readonly.
*
* Sig: `(a: Ary) => boolean`
*/
export default interface IsReadonlyFn extends Fn<[Ary], boolean> {
def: ([a]: Args<this>) => IsReadonly<typeof a>;
}