Skip to main content
Module

x/ts_brand/mod.ts>identity

Reusable type branding in TypeScript
Latest
function identity
import { identity } from "https://deno.land/x/ts_brand@0.0.1/mod.ts";

A generic function that, when given some branded type, can take a value with the base type of the branded type, and cast that value to the branded type. It fulfills the contract of a Brander.

At runtime, this function simply returns the value as-is.

Examples

Example 1

type UserId = Brand<number, 'user'>;
const UserId: Brander<UserId> = identity;

Parameters

underlying: BaseOf<B>

The value with a base type, to be casted

Returns

The same underlying value, but casted