import { isReadonlyOf } from "https://deno.land/x/unknownutil@v3.18.1/mod.ts";
Return an Readonly
annotated type predicate function that returns true
if the type of x
is T
.
This is unstable and may be removed in the future.
Note that this function does nothing but annotate the predicate function as Readonly
.
To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost.
import { is } from "@core/unknownutil";
const isMyType = is.ReadonlyOf(is.TupleOf([is.String, is.Number]));
const a: unknown = ["a", 1];
if (isMyType(a)) {
// a is narrowed to readonly [string, number]
const _: readonly [string, number] = a;
}
Returns
Predicate<Readonly<T>> & WithMetadata<IsReadonlyOfMetadata>