Typescript-compare is a utility library providing TypeScript generic types for comparing types at compile time. Version 0.0.2 offers type-level comparison operators (e.g., eq, lt, gt) and helpers like compare and strictEqual. It enables conditional types based on type equality, ordering, and more, useful for building complex type functions. The library is lightweight, with no runtime dependencies, and is intended for advanced TypeScript type programming. It is released on an as-needed cadence.
npm install typescript-compareVerified import paths — ran on the pinned version, not inferred.
Shows basic usage of type comparison functions eq, compare, and strictEqual for compile-time type checking.
Use only in type contexts (e.g., in type aliases, conditional types).
Consider alternatives like ts-essentials or type-fest for more stable type utilities.
Ensure TypeScript version is at least 2.4.
Make sure to import eq as a named import: import { eq } from 'typescript-compare'Run npm install typescript-compare --save-dev and ensure tsconfig.json includes node_modules.
Use type syntax: type Result = eq<A, B>; not eq(A, B);