assertType
WARNING
Tato funkce nemá žádný vliv za běhu. Pro povolení kontroly typů je nutné použít přepínač --typecheck
.
- Typ:
<T>(value: T): void
Tato funkce slouží jako alternativa k expectTypeOf
a umožňuje snadno ověřit, zda typ argumentu odpovídá zadanému generickému typu.
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 chybné typy
assertType(concat('a', 2));