import { isObjectOf } from "https://deno.land/x/unknownutil@v3.10.0/mod.ts";
Return a type predicate function that returns true
if the type of x
is ObjectOf<T>
.
If is.OptionalOf()
is specified in the predicate function, the property becomes optional.
When options.strict
is true
, the number of keys of x
must be equal to the number of keys of predObj
.
Otherwise, the number of keys of x
must be greater than or equal to the number of keys of predObj
.
import is from "./is.ts";
const predObj = {
a: is.Number,
b: is.String,
c: is.OptionalOf(is.Boolean),
};
const a: unknown = { a: 0, b: "a" };
if (is.ObjectOf(predObj)(a)) {
// a is narrowed to { a: number; b: string; c?: boolean }
const _: { a: number; b: string; c?: boolean } = a;
}
Parameters
predObj: T