Registry / type-stubs / typescript-compare

typescript-compare

JSON →
library0.0.2jsnpmunverified

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-compare
INSTALL
IMPORT
SIG · TYPESCRIPT-COMPARE
T
typescript-compare
type-stubsjavascriptv0.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

eq
import { eq } from 'typescript-compare'
import eq from 'typescript-compare'
Named import for type-level equality check.
compare
import { compare } from 'typescript-compare'
compare takes two types and returns -1, 0, or 1 at type level.
strictEqual
import { strictEqual } from 'typescript-compare'
const strictEqual = require('typescript-compare').strictEqual
ESM-only; does not support CommonJS require.

Shows basic usage of type comparison functions eq, compare, and strictEqual for compile-time type checking.

import { eq, compare, strictEqual } from 'typescript-compare' // Check if two types are equal type TestEqual = eq<number, number> // true type TestNotEqual = eq<number, string> // false // Compare types for ordering (e.g., in conditional types) type CompareResult = compare<number, string> // -1 | 0 | 1 (depending on type order) // Strict equality (no coercion) type Strict = strictEqual<true, true> // true type NotStrict = strictEqual<true, boolean> // false
Debug
Known issues
gotchaOnly works at compile time; no runtime values are exported.
fix
Use only in type contexts (e.g., in type aliases, conditional types).
affects: >=0.0.0
deprecatedThe package may be considered experimental and not widely used.
fix
Consider alternatives like ts-essentials or type-fest for more stable type utilities.
affects: <1.0.0
gotchaTypeScript version compatibility: requires TypeScript 2.4+.
fix
Ensure TypeScript version is at least 2.4.
affects: >=0.0.0
Errors
Common errors & fixes
error TS2304: Cannot find name 'eq'.
Missing or incorrect import statement.
fix
Make sure to import eq as a named import: import { eq } from 'typescript-compare'
error TS2307: Cannot find module 'typescript-compare' or its corresponding type declarations.
Package not installed or TypeScript cannot resolve it.
fix
Run npm install typescript-compare --save-dev and ensure tsconfig.json includes node_modules.
error TS2554: Expected 1 arguments, but got 2.
Using compare or eq incorrectly on runtime values instead of types.
fix
Use type syntax: type Result = eq<A, B>; not eq(A, B);
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies
typescriptoptionalPeer dependency for type definitions; requires TypeScript 2.4+.
Agent activity
30 hits · last 30 days
node
24
OpenAI (training)
1
Resources
typescript-compare — npm install typescript-compare · libregistry