Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/silicon/deps.ts>isObjectOf

Deno module to generate images from source code using Aloxaf/silicon.
Latest
function isObjectOf
import { isObjectOf } from "https://deno.land/x/silicon@v1.0.0/deps.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
optional
unnamed 1: { strict?: boolean; } = [UNSUPPORTED]