Skip to main content
Module

x/unknownutil/util.ts>ensure

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

Ensures that the given value satisfies the provided predicate.

import { ensure, is } from "@core/unknownutil";

const a: unknown = "hello";
const _: string = ensure(a, is.String);

Parameters

x: unknown

The value to be ensured.

pred: Predicate<T>

The predicate function to test the value against.

optional
options: { message?: string; name?: string; } = [UNSUPPORTED]

Optional configuration for the assertion.

Returns

The input value x.