Skip to main content

Type Relation Checker: (Identity, Equivalence, Assignability, Subtyping)

Works with
This package works with Bun
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
It is unknown whether this package works with Browsers
JSR Score
100%
Published
3 weeks ago (1.0.4)

Type Relation Checker

This is a simple utility for checking the type relationships between two types in a TypeScript project.

  • Check subtype (assignment) compatibility: T1 <: T2
  • Check if two types are identical (or equal): T1 = T2
  • Check if two types are equivalent: T1 ≡ T2
  • Check if two types are unrelated: T1 ⊥ T2
  • Check if two types are compatible (checks the above cases at once)

Installation

# deno
deno add @yo-goto/type-relation
# npm
npx jsr add @yo-goto/type-relation

Usage

import {
  Relation,
  IsSubtype,
  IsSupertype,
  IsIdentical,
  IsEquivalent,
  IsUnrelated
} from "@yo-goto/type-relation";

// Check the type relationship between two types
type _0 = Relation<number, string | number>; // => "Subtype"
type _1 = Relation<string | number, number>; // => "Supertype"
type _2 = Relation<number, number>; // => "Identical"
type _3 = Relation<Object, {}>; // => "Equivalent"
type _4 = Relation<"a", "b">; // => "Unrelated"

// Check the type relationship between two types (get true or false type)
type _5 = IsSubtype<number, string | number>; // => true
type _6 = IsSupertype<string | number, number>; // => true
type _7 = IsIdentical<number, number>; // => true
type _8 = IsEquivalent<Object, {}>; // => true
type _9 = IsUnrelated<"a", "b">; // => true
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @yo-goto/type-relation

Import symbol

import * as mod from "@yo-goto/type-relation";

Add Package

npx jsr add @yo-goto/type-relation

Import symbol

import * as mod from "@yo-goto/type-relation";

Add Package

yarn dlx jsr add @yo-goto/type-relation

Import symbol

import * as mod from "@yo-goto/type-relation";

Add Package

pnpm dlx jsr add @yo-goto/type-relation

Import symbol

import * as mod from "@yo-goto/type-relation";

Add Package

bunx jsr add @yo-goto/type-relation

Import symbol

import * as mod from "@yo-goto/type-relation";