typelevel-assert
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

npm version build Gitpod ready-to-code



<TypeLevel> Assert provides convenient assertions for type-level programming.

Usage

Installation

npm i -D typelevel-assert

Start to code (try it out)

import { assertType, Is } from 'typelevel-assert';

type Hi<T extends string> = `Hi ${T}!`;

assertType<Is<Hi<'TypeLevel'>, 'Hi TypeLevel!'>>();

API

The assertType<T>() assertion accepts a type parameter T.

  • The compiler succeeds, if T is true
  • The compiler fails, if T is not true

<TypeLevel> Assert has the following built-in type predicates that can be used with assertType:

type description
And<C1 extends boolean, C extends boolean2> true if both C1 and C2 are true, false otherwise
Or<C1 extends boolean, C2 extends boolean> true if any of C1 or C2 is true, false otherwise
Not<C extends boolean> true if C is false, true otherwise
Equals<T1, T2> And<Extends<T1, T2>, Extends<T2, T1>>
Extends<T1, T2> syntactic sugar for [T1] extends [T2] ? true : false
Is<T1, T2> true if T1 is exactly T2, false otherwise

Package Sidebar

Install

npm i typelevel-assert

Homepage

typelevel.io

Weekly Downloads

3

Version

0.2.2

License

MIT

Unpacked Size

15.8 kB

Total Files

18

Last publish

Collaborators

  • danieldietrich