expectTypeOf & assertType in Vitest
From the Vitest cheat sheet ยท Type Testing ยท verified Nov 2026
expectTypeOf & assertType
Check parameter, return, and object types at compile time
typescript
import { assertType, expectTypeOf, test } from 'vitest'
test('types', () => {
expectTypeOf(add).parameters.toEqualTypeOf<[number, number]>()
expectTypeOf(add).returns.toBeNumber()
expectTypeOf(user).toExtend<{ name: string }>()
assertType<string>(formatName(user))
})๐ *.test-d.ts files are type-checked, never executed
โ ๏ธ toMatchTypeOf is deprecated; use toExtend or toMatchObjectType
๐ toMatchObjectType wants plain object types; interfaces can fail
๐ก @ts-expect-error turns 'this should not compile' into a test
expectTypeOfassertTypetypescript
Continue with Vitest
Save the full cheat sheet or work through every related task.