forked from vitest-dev/vitest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: mention --typecheck flag in docs (vitest-dev#4566)
- Loading branch information
1 parent
d1e1bc9
commit 0a14dd8
Showing
3 changed files
with
324 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,22 @@ | ||
# assertType | ||
|
||
- **Type:** `<T>(value: T): void` | ||
::: warning | ||
During runtime this function doesn't do anything. To [enable typechecking](/guide/testing-types#run-typechecking), don't forget to pass down `--typecheck` flag. | ||
::: | ||
|
||
You can use this function as an alternative for [`expectTypeOf`](/api/expect-typeof) to easily assert that the argument type is equal to the generic provided. | ||
- **Type:** `<T>(value: T): void` | ||
|
||
```ts | ||
import { assertType } from 'vitest' | ||
You can use this function as an alternative for [`expectTypeOf`](/api/expect-typeof) to easily assert that the argument type is equal to the generic provided. | ||
|
||
function concat(a: string, b: string): string | ||
function concat(a: number, b: number): number | ||
function concat(a: string | number, b: string | number): string | number | ||
```ts | ||
import { assertType } from 'vitest' | ||
|
||
assertType<string>(concat('a', 'b')) | ||
assertType<number>(concat(1, 2)) | ||
// @ts-expect-error wrong types | ||
assertType(concat('a', 2)) | ||
``` | ||
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)) | ||
``` |
Oops, something went wrong.