Skip to main content
Module

x/unknownutil/mod.ts>isLiteralOneOf

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

Return a type predicate function that returns true if the type of x is one of literal type in preds.

import { is } from "https://deno.land/x/unknownutil@v3.12.0/mod.ts";

const a: unknown = "hello";
if (is.LiteralOneOf(["hello", "world"] as const)(a)) {
 // a is narrowed to "hello" | "world"
 const _: "hello" | "world" = a;
}

Type Parameters

T extends readonly Primitive[]

Parameters

literals: T