[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
vitest docs api assert-type.md
575 B
Markdown
at commit befbe0c4

assertType #

  • Type: <T>(value: T): void

You can use this function as an alternative for expectTypeOf to easily assert that the argument type is equal to the generic provided.

import { assertType } from 'vitest'

function concat(a: string, b: string): string
function concat(a: number, b: number): number
function concat(a: string | number, b: string | number): string | number

assertType<string>(concat('a', 'b'))
assertType<number>(concat(1, 2))
// @ts-expect-error wrong types
assertType(concat('a', 2))