Skip to main content
Module

x/unknownutil/is.ts>isOptionalOf

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

Return a type predicate function that returns true if the type of x is T or undefined.

import is from "./is.ts";

const a: unknown = "a";
if (is.OptionalOf(is.String)(a)) {
 // a is narrowed to string | undefined
 const _: string | undefined = a;
}