vitest/docs/api/assert-type.md
Vladimir 8b50123014
docs: split API into separate pages (#2635)
* docs: split API into separate pages

* Apply suggestions from code review

Co-authored-by: Anjorin Damilare <damilareanjorin1@gmail.com>

Co-authored-by: Anjorin Damilare <damilareanjorin1@gmail.com>
2023-01-16 15:54:03 +01:00

575 B

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))