Skip to Content
GuidesProgrammatic Usage

Programmatic Usage

Use the programmatic API to run TSTyche from scripts or integrate it with other tools.

Requirements

The lowest supported TypeScript version is 5.4. The module and moduleResolution compiler options must be set to at least "node16".

tstyche/tag

To run TSTyche from within a script or a runtime test, the tstyche/tag entry point provides a tagged template function.

The function runs in the same process, streaming error messages and test results to stderr and stdout in real-time.

Use the --quiet command line option to suppress standard output and focus solely on errors.

Usage

Call the function with the same arguments you would pass to the tstyche command:

import from "tstyche/tag"; // Equivalent to 'tstyche query-params --only multiple' await `query-params --only multiple`;

The function returns a promise that resolves if the test run is successful and rejects if it fails:

import from "node:test"; import from "tstyche/tag"; ("generate types", async () => { const = (import.meta); // ... await `--quiet --root ${}`; });

tstyche/api

The full programmatic API is available from the tstyche/api entry point:

import { Runner } from "tstyche/api"; console.log(Runner.version);

Runner

The tstyche command reads configuration and selects test files before invoking the Runner. The same can be done programmatically:

import { Config, Runner } from "tstyche/api"; const resolvedConfig = Config.resolve(); const runner = new Runner(resolvedConfig); await runner.run(["./typetests/toBeNumber.tst.ts"]);

This is considered a power user feature. To learn more, read the source code  or open an issue with your integration questions.

Last updated on