typescript-test-utils
Helper types for testing your package exported types
- Only depends on typescript installed.
- Easily extendable
Note
I have notice some issues with typescript if your types are too complex, so I recommend using assertTrue
and assertFalse
instead of assert
Usage
You test them with the assert method ( wich is just a placeholder, it doesn't run anything ) and the type helpers
; assertTrue; // okassertTrue; // nopassertFalse; // nopassertFalse; // ok asserttrue; // okasserttrue; // nop ;assertTrue; // okassertFalse; // nopassertTrue; // nopassertFalse; // ok
And just run tsc on your test files to check for type errors
Assertions
There are currently some implemented, if you have any idea for a new one send a PR or open an issue
; HasProperties<, "a" | "b"> // trueHasProperties<, "a" | "c"> // false Extends<,> // trueExtends<,> // false Equals<,> // trueEquals<,> // false Not<true> // falseNot<false> // true Not<Equals<,>> // true
Adding your own assertions
You only need to make a type that returns true or false, for example:
;
or
;
These are the definitions of the Not
and Extends
helpers