0.2.2 • Published 3 years ago
typelevel-assert v0.2.2
<TypeLevel> Assert provides convenient assertions for type-level programming.
Usage
Installation
npm i -D typelevel-assertStart 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
Tistrue - ❌ The compiler fails, if
Tis nottrue
<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 |