import { isRecordOf } from "https://deno.land/x/unknownutil@v3.18.0/is.ts";
Return a type predicate function that returns true
if the type of x
satisfies Record<K, T>
.
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.RecordOf(is.Number);
const a: unknown = {"a": 0, "b": 1};
if (isMyType(a)) {
// a is narrowed to Record<PropertyKey, number>
const _: Record<PropertyKey, number> = a;
}
With predicate function for keys:
import { is } from "@core/unknownutil";
const isMyType = is.RecordOf(is.Number, is.String);
const a: unknown = {"a": 0, "b": 1};
if (isMyType(a)) {
// a is narrowed to Record<string, number>
const _: Record<string, number> = a;
}
Returns
Predicate<Record<K, T>> & WithMetadata<IsRecordOfMetadata>