Guide
Introduction

Introduction

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

Why a Type Test Runner?

Take a look at any popular JavaScript test runner. It is a command line tool. It has test() and describe() helpers with .only and .skip modifiers. It is able to select test files using a pattern or to run a specific test file. And it reports success in green and failures in red.

Now lets look at the typescript package. It consists of the compiler (tsc) and the language server (tsserver). Both of them wrap around the same type checking API. tsc is called from the command line, it emits code and reports found errors in red. tsserver provides information for text editors and reports found errors in red.

Although both of these tools do report errors, their tasks do not include testing types. In other words, neither of them has features that a test runner has. For instance, the compiler does not need an error message like: Type 'X' is not identical to type 'Y'.

Why TSTyche?

The tstyche command is the third member of the team. It wraps around the same type checking APIs, provides type testing experience (similar to your JavaScript test runner that reports success in green and failures in red with specific error messages).

Would you like to use test() and describe() in your tests? Would you like to see green pass printed next to a test file name? Would you like to test your types against several versions of TypeScript?

TSTyche was created, because its author wanted to have a type test runner with all these features. (And more.)

How TSTyche Works?

To be able to test types TSTyche loads the typescript package installed in your project. It checks types programmatically and does not require any dependencies to be installed. This is why the install size of TSTyche is just above 200kB.

TSTyche wraps around TypeScript’s language service API (opens in a new tab) that is designed to do the absolute minimum work required to answer a query. If only a single test file is selected for a run, there is no need to waste time to type check the whole program.

The language service API is also used by text editors like Visual Studio Code. This means that TSTyche sees exactly the same types which you see in hover messages.

Goals of the Project

TSTyche is build to test projects of any size and complexity. It aims to be:

  • lightweight
  • performant
  • predictable
  • scalable

The Name

The name of TSTyche is abbreviated from TypeScript type check. In the early stage of development the library was defined as a type checker. Later it became a type test runner, but the name remained.

In Greek mythology, Tyche (opens in a new tab) was the goddess of fortune and prosperity.