Registry / testing / types-testing

types-testing

JSON →
library1.0.2jsnpmunverified

A runtime type assertion library for testing TypeScript types inside unit test frameworks (Jest, Vitest, Bun). v1.0.2 ships with fast, comment-free assertions like toBe, toBeAny, toBeStringLiteral, and detailed stack traces. Unlike tsd or expect-type, it uses standard expect-style syntax and integrates directly into existing test suites without special comment markers. Released under MIT, with semver releases triggered by PRs. Depends only on TypeScript ^5 || ^6 as a peer dependency. Ships its own TypeScript declarations.

npm install types-testing
INSTALL
IMPORT
SIG · TYPES-TESTING
T
types-testing
testingjavascriptv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TypesTesting
import { TypesTesting } from 'types-testing'
const { TypesTesting } = require('types-testing')
The library is ESM-only; CommonJS require is not supported.
expectType
const { expectType } = new TypesTesting({...}).prepare()
import { expectType } from 'types-testing'
expectType is not a named export; it is returned by prepare(). Do not import directly.
TypesTesting
import TypesTesting from 'types-testing'
Default import is also valid, but named import is preferred for consistency.

Shows instantiation of TypesTesting with basePath/tsConfig, getting expectType from prepare(), and using various type assertions like toBe, toBeStringLiteral, and toEqual.

import { TypesTesting } from 'types-testing'; import { join } from 'node:path'; const basePath = join(process.cwd(), '__tests__'); const { expectType } = new TypesTesting({ basePath, tsConfig: 'tsconfig.json' }).prepare(); describe('types', () => { test('string literal check', () => { expectType('hello').toBe<'hello'>(); expectType('hello').toBeStringLiteral(); }); test('union type narrowing', () => { const value: string | number = Math.random() > 0.5 ? 'text' : 42; expectType(value).toBe<string | number>(); }); test('utility type', () => { type MyPick = Pick<{ a: 1; b: 2 }, 'a'>; expectType<MyPick>().toEqual<{ a: 1 }>(); }); });
Debug
Known issues
breakingThe library is ESM-only; attempting to use require() will throw a runtime error.
fix
Use import syntax in a project configured for ESM (e.g., set "type": "module" in package.json or use .mjs extension).
affects: >=1.0.0
gotchaexpectType is bound to the configuration; you must call prepare() on a TypesTesting instance to obtain it. Direct import of expectType is a common mistake.
fix
Always create an instance and call .prepare() to get the expectType function.
affects: >=1.0.0
gotchaThe basePath and tsConfig options are required; omitting them or providing incorrect paths leads to silent failures or unexpected type resolution.
fix
Set basePath to an absolute path containing your test files and tsConfig to the tsconfig.json relative to basePath.
affects: >=1.0.0
deprecatedNo deprecated features reported; library is in early active development.
Errors
Common errors & fixes
Cannot find module 'types-testing' or its corresponding type declarations.
ESM-only package imported via require() or running in a project without ESM configuration.
fix
Ensure "type": "module" in package.json and use import { TypesTesting } from 'types-testing'.
TypeError: (0 , types_testing_1.TypesTesting) is not a constructor
Default import used with a transpiler that expects CommonJS.
fix
Use the named import: import { TypesTesting } from 'types-testing'.
TypeError: expectType(...).toBe is not a function
expectType was imported directly instead of obtained from prepare().
fix
Call new TypesTesting({...}).prepare() and destructure expectType from the result.
Error: Type check failed: expected type 'string' but got 'number'
The type assertion failed at runtime; the actual type does not match the expected type.
fix
Review the tested value or the expected type argument for correctness.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
typescriptrequiredPeer dependency for type-checking; the library resolves types at runtime
Agent activity
6 hits · last 30 days
node
6
Resources
types-testing — npm install types-testing · libregistry