Skip to content
Vitest 3
Main Navigation Guide & APIConfigBrowser ModeAdvanced API
3.2.0
2.1.9
1.6.1
0.34.6

English

简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

English

简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

Appearance

Sidebar Navigation

Introduction

Why Vitest

Getting Started

Features

Config Reference

API

Test API Reference

Mock Functions

Vi Utility

Expect

ExpectTypeOf

Assert

AssertType

Guides

CLI

Test Filtering

Test Projects

Reporters

Coverage

Snapshot

Mocking

Parallelism

Testing Types

Vitest UI

In-Source Testing

Test Context

Test Annotations

Environment

Extending Matchers

IDE Integration

Debugging

Common Errors

Migration Guide

Migrating to Vitest 3.0

Migrating from Jest

Performance

Profiling Test Performance

Improving Performance

Browser Mode

Node API Reference

Comparisons

On this page

assertType ​

WARNING

During runtime this function doesn't do anything. To enable typechecking, don't forget to pass down --typecheck flag.

  • 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.

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 wrong types
assertType(concat('a', 2));
Pager
Previous pageAssert
Next pageCLI

Released under the MIT License.

Copyright (c) 2021-Present Vitest Team

https://vitest.dev/api/assert-type

Released under the MIT License.

Copyright (c) 2021-Present Vitest Team