Skip to main content
Module

x/unknownutil/util.ts>assert

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

Asserts that the given value satisfies the provided predicate.

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

const a: unknown = "hello";
assert(a, is.String);
// a is now narrowed to string

Parameters

x: unknown

The value to be asserted.

pred: Predicate<T>

The predicate function to test the value against.

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

Optional configuration for the assertion.

Returns

asserts x is T

Nothing. The function has a return type of asserts x is T to help TypeScript narrow down the type of x after the assertion.