Skip to main content
Module

x/unknownutil/mod.ts>isObjectOf

🦕 A lightweight utility pack for handling unknown type
Go to Latest
function isObjectOf
import { isObjectOf } from "https://deno.land/x/unknownutil@v3.2.0/mod.ts";

Return a type predicate function that returns true if the type of x is ObjectOf<T>. 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.Boolean,
};
const a: unknown = { a: 0, b: "a", c: true };
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
optional
options: { strict?: boolean; } = [UNSUPPORTED]