assertType
- Typ:
<T>(value: T): void
Ta funkcja może być używana jako alternatywa dla expectTypeOf
w celu prostego sprawdzenia, czy typ argumentu jest zgodny z określonym typem generycznym.
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 Nieprawidłowe typy
assertType(concat('a', 2));