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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@crbroughton/ts-test-utils

v0.7.0

Published

A collection of testing helper types

Downloads

4

Readme

ts-test-utils

A collection of helper TypeScript types to test other TypeScript types. This collection so far includes:

  • Expect - The main helper; Use this with the below types
  • Equals - Check for equality between two types
  • Assignable - Check if one type is assignable to another type
  • Excludes - Check if a type doesn't contain another type
  • Includes - Check if a type includes another type
  • Extends - Check if one type is extending another type
  • IsArray - Checks if a type is an array
  • IsNotArray - Checks if a type is not an array
  • Length - Check a given types length; Combine this with the 'Equals' type checker
  • Position - Returns a type in the given position of an array; Combine this with the 'Equals' type checker
  • IsNullable - Check if a type is nullable
  • IsNonNullable - Check if a type is not nullable
  • IsUndefined - Check if a type is undefined
  • IsNonUndefined - Check if a type is not undefined
  • IsNullish - Check if a type is either undefined or null
  • IsNonNullish - Check if a type is neither undefined or null
  • IsVoid - Check if a type is void
  • IsNonVoid - Check if a type is not void
  • NonVoid - Remove void from a union that contains void
  • isUnionEqual - Check for equality between two unions

Installation

To install ts-test-utils with Bun, run the following command:

bun i -D @crbroughton/ts-test-utils

Getting Started

You can use these types to test other types:

// This should return true
type Result = Expect<Equals<{ id: number }, { id: number }>>

For testing types that are expected to not equal each-other, you can add the //@ts-expect-error comment to tell the TypeScript compiler that a false return is expected, and that a match is not expected:

// @ts-expect-error - Object / Record failing the equality checker
type ResultRecord = Expect<Equals<{ id: number }, { id: string }>>

You can combine these types with existing types. As an example, here is the 'Equals' type being used to check a functions return type:

function myFunction() {
    return {
        id: 1,
        name: 'Craig',
    }
}
type Result = Expect<Equals<ReturnType<typeof myFunction>, { id: number, name: string }>>

Development Installation

To install dependencies:

bun install

To run:

bun run index.ts

This project was created using bun init in bun v1.1.3. Bun is a fast all-in-one JavaScript runtime.