import { isLiteralOneOf } from "https://deno.land/x/unknownutil@v3.17.1/mod.ts";
Return a type predicate function that returns true
if the type of x
is one of literal type in preds
.
To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost.
import { is } from "https://deno.land/x/unknownutil@v3.17.1/mod.ts";
const isMyType = is.LiteralOneOf(["hello", "world"] as const);
const a: unknown = "hello";
if (isMyType(a)) {
// a is narrowed to "hello" | "world"
const _: "hello" | "world" = a;
}
Type Parameters
T extends readonly Primitive[]
Parameters
literals: T
Returns
Predicate<T[number]> & WithMetadata<IsLiteralOneOfMetadata>