
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 equalitytypeTest=Equal<string,string>// true// Chainable APIcheck<string>().equals<string>()// passes// Assert with clear errorsassert<{a: string}>().hasProperty('a')// Expect syntaxexpect<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
- Property Modifiers - IsReadonly, IsRequired, IsPublic, IsPrivate, IsProtected
- Deep Type Manipulation - DeepReadonly, DeepPartial, RequiredKeys, OptionalKeys
- Function Types - Parameters, ReturnType, Parameter
- Constructor/Abstract - IsConstructor, IsAbstract
- Special Equality - IsNeverEqual
- Chainable API - check(), assert(), expect() for fluent testing
| Type | Description |
|---|---|
Equal<T, U> | Strict equality check |
NotEqual<T, U> | Inequality check |
IsNeverEqual<T, U> | Check if both types are never |
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 |
IsReadonly<T> | Check if all properties are readonly |
IsRequired<T> | Check if all properties are required |
IsPublic<T, K> | Check if property is public |
IsPrivate<T, K> | Check if property is private |
IsProtected<T, K> | Check if property is protected |
DeepReadonly<T> | Make all properties readonly recursively |
DeepPartial<T> | Make all properties optional recursively |
RequiredKeys<T> | Get keys of required properties |
OptionalKeys<T> | Get keys of optional properties |
IsConstructor<T> | Check if type is a constructor |
IsAbstract<T> | Check if type is abstract |
| 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.