npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

asserttt

v1.0.1

Published

---

Readme

asserttt: minimal API for testing types


Table of contents:


Installation

npm install asserttt

asserttt has no non-dev dependencies!

Use cases

Complementary tools

If a file contains type tests, it’s not enough to run it, we must also type-check it:

  • tsx (TypeScript Execute) is a tool that type-checks files before running them.
  • ts-expect-error performs two tasks:
    • Checking if each @ts-expect-error annotation prevents the right kind of error
    • Optional: reporting errors detected by TypeScript
  • Markcheck tests Markdown code blocks.

Usage

import { type Assert, assertType, type Assignable, type Equal, type Extends, type Includes, type Not } from 'asserttt';

//========== Asserting types: Assert<B> ==========

{
  type Pair<X> = [X, X];
  type _1 = Assert<Equal<
    Pair<'a'>, ['a', 'a']
  >>;
  type _2 = Assert<Not<Equal<
    Pair<'a'>, ['x', 'x']
  >>>;
}

{
  type _ = [
    Assert<Assignable<number, 123>>,

    Assert<Extends<Array<string>, Object>>,
    Assert<Not<Extends<Array<string>, RegExp>>>,

    Assert<Includes<'a'|'b', 'a'>>,
    Assert<Includes<'a'|'b'|'c', 'a'|'c'>>,
  ];
}

//========== Asserting types of values: assertType<T>(v)  ==========

const n = 3 + 1;
assertType<number>(n);

API

Asserting

  • Assert<B>
  • assertType<T>(value)

Included predicates (boolean results)

Equality:

  • Equal<X, Y>
  • MutuallyAssignable<X, Y>
  • PedanticEqual<X, Y>

Comparing/detecting types:

  • Extends<Sub, Super>
  • Assignable<Target, Source>
  • Includes<Superset, Subset>
  • IsAny<T>

Boolean operations:

  • Not<B>

How does the code work?

Determining if two types are equal

MutuallyAssignable

export type MutuallyAssignable<X, Y> =
  [X, Y] extends [Y, X] ? true : false
  ;
  • The brackets on the left-hand side of extends prevent distributivity.
  • Almost what we want for checking equality, but any is equal to all types – which is problematic when testing types.

Equal: like MutuallyAssignable but any is only equal to itself

This Equal predicate works well for many use cases:

type Equal<X, Y> =
  [IsAny<X>, IsAny<Y>] extends [true, true] ? true
  : [IsAny<X>, IsAny<Y>] extends [false, false] ? MutuallyAssignable<X, Y>
  : false
  ;
type IsAny<T> = 0 extends (1 & T) ? true : false;

PedanticEqual: a popular hack with several downsides

type PedanticEqual<X, Y> =
  (<T>() => T extends X ? 1 : 2) extends // (A)
  (<T>() => T extends Y ? 1 : 2) ? true : false // (B)
  ;

It was suggested by Matt McCutchen (source). How does it work (source)?

In order to check whether the function type in line A extends the function type in line B, TypeScript has to compare the following two conditional types:

T extends X ? 1 : 2
T extends Y ? 1 : 2

Since T does not have a value, both conditional types are deferred. Assignability of two deferred conditional types is computed via the internal function isTypeIdenticalTo() and only true if:

  1. Both have the same constraint.
  2. Their “then” branches have the same type and their “else” branches have the same type.

Thanks to #1, X and Y are compared precisely.

This hack has several downsides: See test/pedantic-equal_test.ts for more information.

Asserting

type Assert<_T extends true> = void;

Alas, we can’t conditionally produce errors at the type level. That’s why we need to resort to a type parameter whose extends constraint requires it to be assignable to true.

(Idea by Blaine Bublitz)

Related work

  • Package ts-expect inspired this package. It’s very similar. This package uses different names and has a utility type Assert (which doesn’t produce runtime code):

    type _ = Assert<Equal<X,Y>>; // asserttt
    expectType<TypeEqual<X, Y>>(true); // ts-expect
  • The type-challenges repository has a module with utility types for exercises. How is asserttt different?

    • Smaller API
    • Different names
    • Implements boolean NOT via a helper type Not (vs. two versions of the same utility type).
  • eslint-plugin-expect-type supports an elegant notation but requires a special tool (eslint) for checking.