type-assertions is a JavaScript package providing a suite of assertion utilities specifically designed for testing TypeScript types at compile-time. It enables developers to write unit-like tests for their type definitions, ensuring that types behave as expected and catch regressions when refactoring complex type logic. The current stable version is 1.1.0, released in August 2019. This package has a very slow release cadence, with only two minor releases since its inception, indicating a stable and focused utility. Its primary differentiator is its reliance on the TypeScript compiler to validate assertions, providing compile-time feedback rather than runtime checks, which is ideal for validating type system intricacies.
npm install type-assertionsVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import and use various type assertions like `Equal`, `Not`, `Extends`, and `UnionIncludesExact` within a TypeScript file to validate type relationships at compile time.
Use a TypeScript compiler (e.g., `tsc`) to run your type-tests. Failures will manifest as standard TypeScript compilation errors.
Specify a consistent TypeScript version in your project's `package.json` to ensure reproducible type-test results across environments and builds. Regularly test against new TypeScript versions before upgrading.
Carefully consider the implications of assignability versus strict subtyping. For precise subtyping checks, you might need to construct more complex conditional types using `[A] extends [B] ? ...` patterns, though `type-assertions` might not provide direct utilities for all such nuances.
Integrate TypeScript compilation into your CI/CD pipeline. A successful `tsc --noEmit` run without errors indicates all type assertions passed. Tools like `ts-jest` or custom scripts can run `tsc` and report errors.
The assertion itself is incorrect for the types being tested, or the types being tested do not meet the expected contract. Review the types involved and adjust either the type definitions or the assertion logic.
Ensure that `type-assertions` is only used within TypeScript files and that `assert` calls are stripped out during compilation to JavaScript. Do not attempt to invoke `assert` at runtime.
Use `import type { Equal } from 'type-assertions';` for type-only imports or ensure you are using the namespace import correctly, e.g., `ta.Equal<A, B>` after `import * as ta from 'type-assertions';`.No dependency data recorded yet.