Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@crbroughton/ts-test-utils

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@crbroughton/ts-test-utils

A collection of testing helper types

latest
Source
npmnpm
Version
0.7.0
Version published
Maintainers
1
Created
Source

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.

Keywords

typescript

FAQs

Package last updated on 09 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts