🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

tstyche

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tstyche

Everything You Need for Type Testing.

Source
npmnpm
Version
5.0.2
Version published
Weekly downloads
43K
-5.46%
Maintainers
1
Weekly downloads
 
Created
Source

TSTyche

version license install-size coverage

Everything You Need for Type Testing.

TSTyche is a type testing tool for TypeScript. It ships with describe() and test() helpers, expect style assertions and a mighty test runner.

Helpers

If you are used to test JavaScript, a simple type test file should look familiar:

import { expect, test } from "tstyche";

function isSameLength<T extends { length: number }>(a: T, b: T) {
  return a.length === b.length;
}

test("isSameLength", () => {
  expect(isSameLength([1, 2], [1, 2, 3])).type.toBe<boolean>();
  expect(isSameLength("one", "two")).type.toBe<boolean>();

  expect(isSameLength).type.not.toBeCallableWith(1, 2);
});

To organize, debug and plan tests TSTyche has:

  • test(), it() and describe() helpers,
  • with .only, .skip and .todo run mode flags.

Assertions

The assertions can be used to write type tests (like in the above example) or mixed in your unit tests:

import assert from "node:assert";
import test from "node:test";
import * as tstyche from "tstyche";

function toMilliseconds(value: number) {
  if (typeof value === "number" && !Number.isNaN(value)) {
    return value * 1000;
  }

  throw new Error("Not a number");
}

test("toMilliseconds", () => {
  const sample = toMilliseconds(10);

  assert.equal(sample, 10_000);
  tstyche.expect(sample).type.toBe<number>();

  // Will pass as a type test and not throw at runtime
  tstyche.expect(toMilliseconds).type.not.toBeCallableWith("20");
});

Here is the list of all matchers:

  • .toBe(), .toBeAssignableFrom(), .toBeAssignableTo() compare types or types of expression,
  • .toAcceptProps() checks the type of JSX component props,
  • .toBeApplicable ensures that the decorator function can be applied,
  • .toBeCallableWith() checks whether a function is callable with the given arguments,
  • .toBeConstructableWith() checks whether a class is constructable with the given arguments,
  • .toHaveProperty() looks up keys on an object type.

Runner

The tstyche command is the heart of TSTyche. For example, it can select test files by path, filter tests by name and to run the tests against specific versions of TypeScript:

tstyche query-params --only multiple --target '>=5.6'

This simple! (And it has watch mode too.)

Documentation

Visit tstyche.org to view the full documentation.

License

MIT © TSTyche

Keywords

typescript

FAQs

Package last updated on 08 Dec 2025

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