Skip to main content
Module

x/typeguardkit/mod.ts>assertIs

A TypeScript module to help construct type assertion functions and type guards.
Latest
function assertIs
import { assertIs } from "https://deno.land/x/typeguardkit@0.32.1/mod.ts";

assertIs wraps asserter with an assertion signature so value can be narrowed to Type. If asserter.assert throws an error, it will bubble up. Otherwise, assertIs will not return a value, but after calling it, value will be narrowed to Type.

Example:

import { _string, assertIs } from "typeguardkit";

function handleUnknown(x: unknown) {
  assertIs(_string, x, "x");

  handleString(x);
}

function handleString(x: string) {};

Parameters

asserter: Asserter<Type>
value: unknown
optional
valueName: string

Returns

asserts value is Type