A micro library for compile-time type testing in TypeScript.
- TypeScript 5.0+
# Install type-testing
npm install @deessejs/type-testing
# Or using pnpm
pnpm add @deessejs/type-testing
# Or using yarn
yarn add @deessejs/type-testingimport { Equal, check, assert, expect } from '@deessejs/type-testing'
// Simple type equality
type Test = Equal<string, string> // true
// Chainable API
check<string>().equals<string>() // passes
// Assert with clear errors
assert<{ a: string }>().hasProperty('a')
// Expect syntax
expect<string, string>().toBeEqual()- Type Equality - Strict and simple equality checks
- Special Type Detection - IsAny, IsNever, IsUnknown, IsVoid, etc.
- Union/Tuple/Array Detection - IsUnion, IsTuple, IsArray
- Type Inhabitation - IsInhabited, IsUninhabited
- Property Testing - HasProperty, PropertyType
- Function Types - Parameters, ReturnType, Parameter
- Chainable API - check(), assert(), expect() for fluent testing
| Type | Description |
|---|---|
Equal<T, U> |
Strict equality check |
NotEqual<T, U> |
Inequality check |
IsAny<T> |
Check if type is any |
IsNever<T> |
Check if type is never |
IsUnknown<T> |
Check if type is unknown |
IsNullable<T> |
Check if type is null | undefined |
IsUnion<T> |
Check if type is a union |
IsTuple<T> |
Check if type is a tuple |
IsArray<T> |
Check if type is an array |
| Function | Description |
|---|---|
check<T>() |
Create a chainable type checker |
assert<T>() |
Create an assert type checker (throws on failure) |
expect<T, U>() |
Create an expect-style type checker |
For complete documentation, see packages/type-testing/README.md
Contributions are welcome! Please feel free to submit a Pull Request.
- Nesalia Inc.
If you discover any security vulnerabilities, please send an e-mail to security@nesalia.com.
MIT License - see the LICENSE file for details.