Skip to main content
Module

x/unknownutil/mod.ts>isOmitOf

🦕 A lightweight utility pack for handling unknown type
Go to Latest
function isOmitOf
import { isOmitOf } 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 Omit<ObjectOf<T>, K>.

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.OmitOf(is.ObjectOf({
  a: is.Number,
  b: is.String,
  c: is.OptionalOf(is.Boolean),
}), ["a", "c"]);
const a: unknown = { a: 0, b: "a", other: "other" };
if (isMyType(a)) {
  // The "a", "c", and "other" key in `a` is ignored.
  // 'a' is narrowed to { b: string }
  const _: { b: string } = a;
}

Type Parameters

T extends Record<PropertyKey, unknown>
K extends keyof T

Parameters

pred: Predicate<T> & WithMetadata<IsObjectOfMetadata>
keys: K[]

Returns

Predicate<FlatType<Omit<T, K>>> & WithMetadata<IsObjectOfMetadata>