Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/typeguardkit/mod.ts>is

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

is wraps asserter with a predicate signature, creating a type guard, so that value can be narrowed to Type. If asserter.assert throws an error, is will catch it and return false. Otherwise, is will return true.

Example:

import { _string, is } from "typeguardkit";

function handleUnknown(x: unknown) {
  if (is(_string, x)) {
    handleString(x);
  }
}

function handleString(x: string) {}

Parameters

asserter: Asserter<Type>
value: unknown

Returns

value is Type