diff --git a/docs/guide/migration.md b/docs/guide/migration.md index a9632f368..b0cb9d317 100644 --- a/docs/guide/migration.md +++ b/docs/guide/migration.md @@ -41,6 +41,13 @@ This means callback parameters can be inferred as literal unions (for example `1 If your callback annotations intentionally reject literal values and relied on wider inference, update those annotations to accept the inferred literal unions. +```ts +test.each([1, 2])('value %s', (num) => { + expectTypeOf(num).toEqualTypeOf() // [!code --] + expectTypeOf(num).toEqualTypeOf<1 | 2>() // [!code ++] +}) +``` + ### Locators in Commands are Serialized as Objects Locators forwarded to [browser commands](/api/browser/commands) are now serialized as a `SerializedLocator` object instead of a bare selector string. The object exposes two fields: diff --git a/test/typescript/fixtures/dynamic-title/test/dynamic-title.test-d.ts b/test/typescript/fixtures/dynamic-title/test/dynamic-title.test-d.ts index 71095e238..19d62fbd2 100644 --- a/test/typescript/fixtures/dynamic-title/test/dynamic-title.test-d.ts +++ b/test/typescript/fixtures/dynamic-title/test/dynamic-title.test-d.ts @@ -1,19 +1,9 @@ -import { describe, expectTypeOf, test } from 'vitest' +import { expectTypeOf, test } from 'vitest' test.each(['some-value'])('each: %s', () => { expectTypeOf(1).toEqualTypeOf(2) }) -test.each([1, 2])('each literal number: %s', (num) => { - expectTypeOf(num).toEqualTypeOf<1 | 2>() -}) - -describe.each([1, 2])('describe.each literal number: %s', (num) => { - test('keeps literal union', () => { - expectTypeOf(num).toEqualTypeOf<1 | 2>() - }) -}) - test.for(['some-value'])('for: %s', () => { expectTypeOf(1).toEqualTypeOf(2) }) diff --git a/test/unit/test/each.test.ts b/test/unit/test/each.test.ts index 675d97140..51092cb17 100644 --- a/test/unit/test/each.test.ts +++ b/test/unit/test/each.test.ts @@ -23,6 +23,10 @@ test.each([1, 2])('preserves literal unions for test.each', (num) => { expectTypeOf(num).toEqualTypeOf<1 | 2>() }) +test.for([1, 2])('preserves literal unions for test.for', (num) => { + expectTypeOf(num).toEqualTypeOf<1 | 2>() +}) + describe.each([ [1, 1, 2], [1, 2, 3], @@ -47,6 +51,12 @@ describe.each([1, 2])('preserves literal unions for describe.each', (num) => { }) }) +describe.for([1, 2])('preserves literal unions for describe.for', (num) => { + test('literal union type', () => { + expectTypeOf(num).toEqualTypeOf<1 | 2>() + }) +}) + describe.each([ [1, 'a', '1a'], [1, 'b', '1b'],