[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix(types): cover literal inference for for APIs and adjust migration docs

Agent-Logs-Url: https://github.com/vitest-dev/vitest/sessions/ac00e58b-ca26-4e4f-b60c-42e25fad91b0

Co-authored-by: sheremet-va <16173870+sheremet-va@users.noreply.github.com>

authored by

copilot-swe-agent[bot]
sheremet-va
and committed by
GitHub
(May 7, 2026, 3:32 PM UTC) df136594 f6df5bdb

+9 -8
+5 -4
docs/guide/migration.md
··· 42 42 If your callback annotations intentionally reject literal values and relied on wider inference, update those annotations to accept the inferred literal unions. 43 43 44 44 ```ts 45 - test.each([1, 2])('value %s', (num) => { 46 - expectTypeOf(num).toEqualTypeOf<number>() // [!code --] 47 - expectTypeOf(num).toEqualTypeOf<1 | 2>() // [!code ++] 48 - }) 45 + // Vitest 5 infers `value` as `1 | 2`, so this callback is now too narrow: 46 + test.each([1, 2])('value %s', (value: Exclude<number, 1 | 2>) => {}) // [!code --] 47 + 48 + // If you need the previous wide inference, specify the case type explicitly: 49 + test.each<number>([1, 2])('value %s', (value: Exclude<number, 1 | 2>) => {}) // [!code ++] 49 50 ``` 50 51 51 52 ### Locators in Commands are Serialized as Objects
+1 -1
test/unit/test/test-for-suite.test.ts
··· 4 4 'basic %s', 5 5 (...args) => { 6 6 test('test', () => { 7 - expectTypeOf(args).toEqualTypeOf<[string]>() 7 + expectTypeOf(args).toEqualTypeOf<['case1' | 'case2']>() 8 8 expect({ args }).matchSnapshot() 9 9 }) 10 10 },
+1 -1
test/unit/test/test-for.test.ts
··· 32 32 }, 33 33 ) 34 34 35 - myTest.concurrent.for(['case1', 'case2'] as const)( 35 + myTest.concurrent.for(['case1', 'case2'])( 36 36 'const %s', 37 37 (args, { expect, myFixture }) => { 38 38 expectTypeOf(args).toEqualTypeOf<'case1' | 'case2'>()
+2 -2
packages/runner/src/types/tasks.ts
··· 420 420 interface TestForFunction<ExtraContext> { 421 421 // test.for([1, 2, 3]) 422 422 // test.for([[1, 2], [3, 4, 5]]) 423 - <T>(cases: ReadonlyArray<T>): TestForFunctionReturn< 423 + <const T>(cases: ReadonlyArray<T>): TestForFunctionReturn< 424 424 T, 425 425 TestContext & ExtraContext 426 426 > ··· 437 437 } 438 438 439 439 interface SuiteForFunction { 440 - <T>(cases: ReadonlyArray<T>): EachFunctionReturn<[T]> 440 + <const T>(cases: ReadonlyArray<T>): EachFunctionReturn<[T]> 441 441 (...args: [TemplateStringsArray, ...any]): EachFunctionReturn<any[]> 442 442 } 443 443