diff --git a/tests/playwright-test/types.spec.ts b/tests/playwright-test/types.spec.ts index 89cdc7a1b2..234eb9b23b 100644 --- a/tests/playwright-test/types.spec.ts +++ b/tests/playwright-test/types.spec.ts @@ -37,6 +37,16 @@ test('should check types of fixtures', async ({runTSC}) => { const good7 = test.extend<{ baz: boolean }>({ baz: [ false, { auto: true } ], }); + const good8 = test.extend<{ foo: string }>({ + foo: [ async ({}, use) => { + await use('foo'); + }, { scope: 'test' } ], + }); + const good9 = test.extend<{}, {}>({ + bar: [ async ({}, use) => { + await use(42); + }, { scope: 'worker' } ], + }); // @ts-expect-error const fail1 = test.extend<{}>({ foo: 42 }); @@ -60,6 +70,18 @@ test('should check types of fixtures', async ({runTSC}) => { // @ts-expect-error baz: true, }); + const fail9 = test.extend<{ foo: string }>({ + foo: [ async ({}, use) => { + await use('foo'); + // @ts-expect-error + }, { scope: 'test', auto: true } ], + }); + const fail10 = test.extend<{}, {}>({ + bar: [ async ({}, use) => { + await use(42); + // @ts-expect-error + }, { scope: 'test' } ], + }); `, 'playwright.config.ts': ` import { MyOptions } from './helper'; diff --git a/types/test.d.ts b/types/test.d.ts index 1c2fcd57d2..32b9764ff6 100644 --- a/types/test.d.ts +++ b/types/test.d.ts @@ -2142,9 +2142,9 @@ export type WorkerFixture = (args: Args, use: (r: R) = type TestFixtureValue = R | TestFixture; type WorkerFixtureValue = R | WorkerFixture; export type Fixtures = { - [K in keyof PW]?: WorkerFixtureValue; + [K in keyof PW]?: WorkerFixtureValue | [WorkerFixtureValue, { scope: 'worker' }]; } & { - [K in keyof PT]?: TestFixtureValue; + [K in keyof PT]?: TestFixtureValue | [TestFixtureValue, { scope: 'test' }]; } & { [K in keyof W]?: [WorkerFixtureValue, { scope: 'worker', auto?: boolean }]; } & { diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.ts index a0d3a5469b..9cf4363f3f 100644 --- a/utils/generate_types/overrides-test.d.ts +++ b/utils/generate_types/overrides-test.d.ts @@ -265,9 +265,9 @@ export type WorkerFixture = (args: Args, use: (r: R) = type TestFixtureValue = R | TestFixture; type WorkerFixtureValue = R | WorkerFixture; export type Fixtures = { - [K in keyof PW]?: WorkerFixtureValue; + [K in keyof PW]?: WorkerFixtureValue | [WorkerFixtureValue, { scope: 'worker' }]; } & { - [K in keyof PT]?: TestFixtureValue; + [K in keyof PT]?: TestFixtureValue | [TestFixtureValue, { scope: 'test' }]; } & { [K in keyof W]?: [WorkerFixtureValue, { scope: 'worker', auto?: boolean }]; } & {