import { isLiteralOf } 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 a literal type of pred
.
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.LiteralOf("hello");
const a: unknown = "hello";
if (isMyType(a)) {
// a is narrowed to "hello"
const _: "hello" = a;
}
Type Parameters
T extends Primitive
Parameters
literal: T
Returns
Predicate<T> & WithMetadata<IsLiteralOfMetadata>