Skip to main content
Module

x/unknownutil/mod.ts>isSetOf

🦕 A lightweight utility pack for handling unknown type
Go to Latest
function isSetOf
import { isSetOf } 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 Set<T>.

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.SetOf(is.String);
const a: unknown = new Set(["a", "b", "c"]);
if (isMyType(a)) {
  // a is narrowed to Set<string>
  const _: Set<string> = a;
}

Returns

Predicate<Set<T>> & WithMetadata<IsSetOfMetadata>