import { isRequiredOf } from "https://deno.land/x/unknownutil@v3.18.0/is.ts";
Return a type predicate function that returns true
if the type of x
is Required<ObjectOf<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.RequiredOf(is.ObjectOf({
a: is.Number,
b: is.UnionOf([is.String, is.Undefined]),
c: is.OptionalOf(is.Boolean),
}));
const a: unknown = { a: 0, b: "b", c: true, other: "other" };
if (isMyType(a)) {
// 'a' is narrowed to { a: number; b: string | undefined; c: boolean }
const _: { a: number; b: string | undefined; c: boolean } = a;
}
Parameters
pred: Predicate<T> & WithMetadata<IsObjectOfMetadata>
Returns
Predicate<FlatType<Required<T>>> & WithMetadata<IsObjectOfMetadata>