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.fixUse 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.fixAlways 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.fixSet 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.
fixEnsure "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.
fixUse the named import: import { TypesTesting } from 'types-testing'. TypeError: expectType(...).toBe is not a function
expectType was imported directly instead of obtained from prepare().
fixCall 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.
fixReview the tested value or the expected type argument for correctness.
Audit
Dependencies
typescriptrequiredPeer dependency for type-checking; the library resolves types at runtime