Types for testing TypeScript types.
npm install conditional-type-checks



As TypeScript's type system becomes more complex, it's useful to be able to write tests for what a type should be.
This library offers reusable conditional types to help test your types.
These will resolve to the type true when they match and false otherwise.
- IsNullable - Checks if T is possibly null or undefined.
- IsExact - Checks if T exactly matches U.
- Has - Checks if T has U.
- NotHas - Checks if T does not have U.
- IsAny - Checks if T is the any type.
- IsNever - Checks if T is the never type.
- IsUnknown - Checks if T is the unknown type.
- More to come...
Use what you prefer:
1. The AssertTrue, AssertFalse, or Assert types.
2. The assert function.
Doing a test:
``ts
import type {
AssertFalse,
AssertTrue,
Has,
IsNever,
IsNullable,
} from "https://deno.land/x/conditional_type_checks/mod.ts";
const result = someFunction(someArg);
type _test =
| AssertTrue
| AssertFalse
| Assert
`
Warning: Do not use an intersection type between checks (ex. Has) because it will cause everything to pass if only one of the checks passes.
Doing a test:
`ts
import {
assert,
IsExact,
} from "https://deno.land/x/conditional_type_checks/mod.ts";
const result = someFunction(someArg);
// compile error if the type of result is not exactly string | number`
assert
Failure:
`tstrue
// causes a compile error that is not assignable to false`
assert
```
npm install --save-dev conditional-type-checks