Skip to main content
Deno 2 is finally here 🎉️
Learn more
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.33.0/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