assertType
- Type:
<T>(value: T): void
Cette fonction offre une alternative à expectTypeOf
pour vérifier simplement que le type de l'argument correspond au type générique spécifié.
ts
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 Types incompatibles
assertType(concat('a', 2));