import { isStrictOf } from "https://deno.land/x/unknownutil@v3.18.0/mod.ts";
Return a type predicate function that returns true
if the type of x
is strictly follow the ObjectOf<T>
.
To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost.
If is.OptionalOf()
is specified in the predicate function, the property becomes optional.
The number of keys of x
must be equal to the number of non optional keys of predObj
. This is equivalent to
the deprecated options.strict
in isObjectOf()
.
import { is } from "@core/unknownutil";
const isMyType = is.StrictOf(is.ObjectOf({
a: is.Number,
b: is.String,
c: is.OptionalOf(is.Boolean),
}));
const a: unknown = { a: 0, b: "a", other: "other" };
if (isMyType(a)) {
// This block will not be executed because of "other" key in `a`.
}
Parameters
pred: Predicate<T> & WithMetadata<IsObjectOfMetadata>
Returns
Predicate<T> & WithMetadata<IsStrictOfMetadata>