Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Oct 10, 2024
1 parent 0795811 commit 70f17f8
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,18 +368,26 @@ export default defineConfig({

#### TypeScript integration

To ensure TypeScript recognizes the global APIs, you have two options:
To ensure TypeScript recognizes the global APIs, you can choose one of the following options:

1. Import the global types
1. Use a `@types/vitest.d.ts` file

Import `vitest/globals` from any `.ts` file (e.g., your [setup file](#setupfiles) or a `.d.ts` file). This registers the global APIs types automatically. Ensure the file is included in your `tsconfig.json` so TypeScript knows it's apart of the same project.
Create a `@types/vitest.d.ts` file in your project root that imports `vitest/globals`:

```ts
// test-setup.ts or vitest.d.ts
import 'vitest/globals'
```

2. Configure it in [`tsconfig.json#compilerOptions.types`](https://www.typescriptlang.org/tsconfig/#types)
2. Type-import the global types from a source file

Add a type-import from `vitest/globals` in any `.ts` file (e.g., your [setup file](#setupfiles)). This registers the global APIs types automatically. Ensure the file is included in your `tsconfig.json` so TypeScript knows it's apart of the same project.

```ts
// test-setup.ts
import type {} from 'vitest/globals'
```

3. Configure it in [`tsconfig.json#compilerOptions.types`](https://www.typescriptlang.org/tsconfig/#types)

Alternatively, add `vitest/globals` to the `types` field in `tsconfig.json`.

Expand Down

0 comments on commit 70f17f8

Please sign in to comment.