From 30684a77e764c49aa76ece4af628ef0aaf1f38e5 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Thu, 8 Aug 2024 09:11:44 -0700 Subject: [PATCH] cherry-pick(#32066): fix(types): revert type changes made to support TS 5.5 (#32080) Regressed in #31532. The TS5.5 changes broke chaining of `extend`s where the first `extend` did not specify any type arguments. Fixes #32056. --- packages/playwright/types/test.d.ts | 4 ++-- tests/library/global-fetch.spec.ts | 2 +- tests/playwright-test/types.spec.ts | 20 +++++++++++++++++--- utils/generate_types/overrides-test.d.ts | 4 ++-- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts index c5a3f5d9dd80a..28bc7798b59f5 100644 --- a/packages/playwright/types/test.d.ts +++ b/packages/playwright/types/test.d.ts @@ -4815,9 +4815,9 @@ export type Fixtures | [TestFixtureValue, { scope: 'test', timeout?: number | undefined, title?: string, box?: boolean }]; } & { - [K in Exclude]?: [WorkerFixtureValue, { scope: 'worker', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }]; + [K in keyof W]?: [WorkerFixtureValue, { scope: 'worker', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }]; } & { - [K in Exclude]?: TestFixtureValue | [TestFixtureValue, { scope?: 'test', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }]; + [K in keyof T]?: TestFixtureValue | [TestFixtureValue, { scope?: 'test', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }]; }; type BrowserName = 'chromium' | 'firefox' | 'webkit'; diff --git a/tests/library/global-fetch.spec.ts b/tests/library/global-fetch.spec.ts index b3bea9e432994..5de98fe9ee467 100644 --- a/tests/library/global-fetch.spec.ts +++ b/tests/library/global-fetch.spec.ts @@ -21,7 +21,7 @@ import { expect, playwrightTest as base } from '../config/browserTest'; import { kTargetClosedErrorMessage } from 'tests/config/errors'; const it = base.extend({ - context: async () => { + context: async ({}, use) => { throw new Error('global fetch tests should not use context'); } }); diff --git a/tests/playwright-test/types.spec.ts b/tests/playwright-test/types.spec.ts index da8d88a38bf6f..c34c586f7a0ad 100644 --- a/tests/playwright-test/types.spec.ts +++ b/tests/playwright-test/types.spec.ts @@ -19,7 +19,7 @@ import { test, expect } from './playwright-test-fixtures'; test('should check types of fixtures', async ({ runTSC }) => { const result = await runTSC({ 'helper.ts': ` - import { test as base, expect } from '@playwright/test'; + import { test as base, expect, Page } from '@playwright/test'; export type MyOptions = { foo: string, bar: number }; export const test = base.extend<{ foo: string }, { bar: number }>({ foo: 'foo', @@ -71,7 +71,7 @@ test('should check types of fixtures', async ({ runTSC }) => { // @ts-expect-error baz: true, }); - const fail9 = test.extend<{ foo: string }>({ + const fail9 = test.extend({ foo: [ async ({}, use) => { await use('foo'); // @ts-expect-error @@ -100,7 +100,21 @@ test('should check types of fixtures', async ({ runTSC }) => { return y; }); }, - }) + }); + + const chain1 = base.extend({ + page: async ({ page }, use) => { + await use(page); + }, + }); + const chain2 = chain1.extend<{ pageAsUser: Page }>({ + pageAsUser: async ({ page }, use) => { + // @ts-expect-error + const x: number = page; + // @ts-expect-error + await use(x); + }, + }); `, 'playwright.config.ts': ` import { MyOptions } from './helper'; diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.ts index 3a42d27f83e6d..5c108d7b2591a 100644 --- a/utils/generate_types/overrides-test.d.ts +++ b/utils/generate_types/overrides-test.d.ts @@ -144,9 +144,9 @@ export type Fixtures | [TestFixtureValue, { scope: 'test', timeout?: number | undefined, title?: string, box?: boolean }]; } & { - [K in Exclude]?: [WorkerFixtureValue, { scope: 'worker', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }]; + [K in keyof W]?: [WorkerFixtureValue, { scope: 'worker', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }]; } & { - [K in Exclude]?: TestFixtureValue | [TestFixtureValue, { scope?: 'test', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }]; + [K in keyof T]?: TestFixtureValue | [TestFixtureValue, { scope?: 'test', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }]; }; type BrowserName = 'chromium' | 'firefox' | 'webkit';