UNPKG

types-testing

Version:

Test TypeScript types at test runner runtime - Works seamlessly with Jest, Vitest, and Bun.

92 lines (91 loc) 2.95 kB
import type { Assertions } from '../definitions/__internal/assertions'; import type { NotProvided } from '../definitions/__internal/not-provided'; import type ts from 'typescript'; /** * Blueprint class for types-testing implementation. */ export declare class TypesTesting { #private; /** * Creates a new types-testing instance. * * @param options Options for types-testing instance. */ constructor(options: TypesTestingOptions); /** * Checks if the types-testing instance is ready (prepared). */ get isPrepared(): boolean; /** * Gets the current configuration options. */ get options(): TypesTestingOptions; /** * Prepares the types-testing instance. * * @param options Optional options to override instance options. * @throws If the `tsconfig.json` file can't be found. */ prepare(options?: Partial<Omit<TypesTestingOptions, 'autoPrepare'>>): this; /** * Reset the types-testing instance. * * Will do nothing if the types-testing instance is not prepared. * * @param runPrepare Optional boolean flag to specify whether to run {@link prepare} after reset. */ reset(runPrepare?: boolean): void; /** * Returns assertion functions for checking types. * * @template Received The received type. * @param received The received value (only the value type will be used). * @returns Set of assertions object. * @throws If the tester isn't prepared (i.e., `prepare()` hasn't been called yet). */ expectType<Received = NotProvided>(received?: Received): Assertions<Received>; } /** * Options for types-testing instance creation. */ export type TypesTestingOptions = { /** * Whether to run prepare when the `expectType` function is first called. Defaults to `true`. * * **Note**: * * It's better to run prepare manually * if `expectType` is called inside test suite to prevent test timeout. */ autoPrepare?: boolean; /** * Define the base path. * * Optional if directly using `compilerOptions` and `files`. */ basePath?: string; /** * Define the name of tsconfig file. * * Optional if directly using `compilerOptions` and `files`. */ tsConfig?: string; /** * Define typescript compiler options or extends typescript compiler options from tsconfig file. * * Optional if using `basePath` and `tsConfig`. */ compilerOptions?: Partial<ts.CompilerOptions>; /** * Define typescript included files or extends included files from tsconfig file. * * Optional if using `basePath` and `tsConfig`. */ files?: readonly string[]; /** * Define typescript project references or extends project references from tsconfig file. * * Always optional. */ projectReferences?: readonly ts.ProjectReference[]; };