Skip to main content
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.32.1/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