type-testing

Write compile-time type assertions with Vitest expectTypeOf alongside runtime tests.

Updated Sep 15, 2026
One-click install
npx skills add https://github.com/tomada1114/quick-reply-drill --skill type-testing-tomada1114
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: type-testing
Source: https://github.com/tomada1114/quick-reply-drill/tree/main/.agents/skills/type-testing
Command: npx skills add https://github.com/tomada1114/quick-reply-drill --skill type-testing-tomada1114

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Type-level assertions in TypeScript test suites often silently pass without proving anything: a @ts-expect-error can be satisfied by the wrong error, a union initializer narrows before the assertion runs, and an annotated generic export can be wider than its inferred type. This Skill defines where type assertions belong, what is worth asserting, and how to avoid the traps that make them vacuous. ## Core Features & Use Cases - Placement rules: Keep expectTypeOf assertions in the same Vitest suite as the runtime tests for the surface they check, so a signature change breaks both halves in one place. - Assertion patterns: Assert that generics do not widen, that discriminated unions narrow on their discriminant, that invalid inputs fail to compile, and that as const satisfies literal lists stay in step with a union. - Trap avoidance: Handle the three failure modes — @ts-expect-error inside it() still executing, union initializers narrowing before assertion, and @ts-expect-error being satisfied by the wrong error. - Use Case: When adding a new member to the LlmErrorCode union, write a type test comparing the ALL_CODES manifest against the union so a forgotten case fails at compile time. ## Quick Start Ask the AI to add a type test for a changed exported function signature using expectTypeOf in the existing test suite for that module.

Frequently Asked Questions about type-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write type tests with Vitest expectTypeOf?▼

Place expectTypeOf assertions in the same test suite as the runtime tests for the surface they check, inside an it() block with no runtime expect needed. Assert on concrete calls, such as expectTypeOf(value).toEqualTypeOf<{ answer: string }>(), to prove a generic was not widened.

How do I test that invalid TypeScript input fails to compile?▼

Use @ts-expect-error on the invalid call, but declare it inside a function that is never invoked so the body is type-checked without executing. Pair it with an expectTypeOf assertion on the correct call so the test still fails if the error moves to a different cause.

Why does my @ts-expect-error test pass for the wrong reason?▼

@ts-expect-error only asserts that the next line fails to compile, not why. A typo'd property name satisfies it just as a genuine type violation does, so pair it with an expectTypeOf assertion on the correct call and include a descriptive comment of at least ten characters.

Why does a union type assertion not test narrowing?▼

TypeScript narrows a const on its initializer, so const result: Result<T, E> = { ok: false, error } infers only the failure member. Receive the value as a function parameter instead, so the parameter annotation is what narrowing is checked against.

What are the limitations of compile-time type assertions?▼

Type assertions are erased before anything runs, so they say nothing about whether runtime values match the types. They also do not cover framework entry points like Next.js App Router pages, which are type-checked by the build rather than by tests.