Skip to content

Commit

Permalink
cherry-pick(#32066): fix(types): revert type changes made to support …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
dgozman authored Aug 8, 2024
1 parent 5e68061 commit 30684a7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/playwright/types/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4815,9 +4815,9 @@ export type Fixtures<T extends KeyValue = {}, W extends KeyValue = {}, PT extend
} & {
[K in keyof PT]?: TestFixtureValue<PT[K], T & W & PT & PW> | [TestFixtureValue<PT[K], T & W & PT & PW>, { scope: 'test', timeout?: number | undefined, title?: string, box?: boolean }];
} & {
[K in Exclude<keyof W, keyof PW>]?: [WorkerFixtureValue<W[K], W & PW>, { scope: 'worker', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }];
[K in keyof W]?: [WorkerFixtureValue<W[K], W & PW>, { scope: 'worker', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }];
} & {
[K in Exclude<keyof T, keyof PT>]?: TestFixtureValue<T[K], T & W & PT & PW> | [TestFixtureValue<T[K], T & W & PT & PW>, { scope?: 'test', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }];
[K in keyof T]?: TestFixtureValue<T[K], T & W & PT & PW> | [TestFixtureValue<T[K], T & W & PT & PW>, { scope?: 'test', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }];
};

type BrowserName = 'chromium' | 'firefox' | 'webkit';
Expand Down
2 changes: 1 addition & 1 deletion tests/library/global-fetch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});
Expand Down
20 changes: 17 additions & 3 deletions tests/playwright-test/types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions utils/generate_types/overrides-test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ export type Fixtures<T extends KeyValue = {}, W extends KeyValue = {}, PT extend
} & {
[K in keyof PT]?: TestFixtureValue<PT[K], T & W & PT & PW> | [TestFixtureValue<PT[K], T & W & PT & PW>, { scope: 'test', timeout?: number | undefined, title?: string, box?: boolean }];
} & {
[K in Exclude<keyof W, keyof PW>]?: [WorkerFixtureValue<W[K], W & PW>, { scope: 'worker', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }];
[K in keyof W]?: [WorkerFixtureValue<W[K], W & PW>, { scope: 'worker', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }];
} & {
[K in Exclude<keyof T, keyof PT>]?: TestFixtureValue<T[K], T & W & PT & PW> | [TestFixtureValue<T[K], T & W & PT & PW>, { scope?: 'test', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }];
[K in keyof T]?: TestFixtureValue<T[K], T & W & PT & PW> | [TestFixtureValue<T[K], T & W & PT & PW>, { scope?: 'test', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }];
};

type BrowserName = 'chromium' | 'firefox' | 'webkit';
Expand Down

0 comments on commit 30684a7

Please sign in to comment.