From 70f17f8eeddd9e3420ec480e5d70be603ae613ae Mon Sep 17 00:00:00 2001 From: Hiroki Osame Date: Thu, 10 Oct 2024 13:41:43 +0900 Subject: [PATCH] wip --- docs/config/index.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 9e2d220a9e811..d95bbc7bf58e2 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -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`.