From 9c6c31a442002fa5a6d3f6d493ea799082ec5dd8 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Tue, 31 Jan 2023 15:02:01 -0800 Subject: [PATCH] fix(types): update PlaywrightTestConfig types (#20540) This makes errors more focused on the custom properties. References #20416. --- packages/playwright-test/types/test.d.ts | 9 +- tests/playwright-test/types.spec.ts | 101 ++++++++++++++++++++++- utils/generate_types/overrides-test.d.ts | 9 +- 3 files changed, 114 insertions(+), 5 deletions(-) diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.ts index 0d0a79b1fc..f597c69c6d 100644 --- a/packages/playwright-test/types/test.d.ts +++ b/packages/playwright-test/types/test.d.ts @@ -3724,8 +3724,13 @@ export interface PlaywrightTestArgs { request: APIRequestContext; } -export type PlaywrightTestProject = Project; -export type PlaywrightTestConfig = Config; +type ExcludeProps = { + [K in Exclude]: A[K]; +}; +type CustomProperties = ExcludeProps; + +export type PlaywrightTestProject = Project, PlaywrightWorkerOptions & CustomProperties>; +export type PlaywrightTestConfig = Config, PlaywrightWorkerOptions & CustomProperties>; import type * as expectType from './expect-types'; import type { Suite } from './testReporter'; diff --git a/tests/playwright-test/types.spec.ts b/tests/playwright-test/types.spec.ts index 67d9adb715..2ba12c2618 100644 --- a/tests/playwright-test/types.spec.ts +++ b/tests/playwright-test/types.spec.ts @@ -166,7 +166,106 @@ test('should check types of fixtures', async ({ runTSC }) => { test.afterAll(async ({ a }) => {}); test.afterAll(async ({ foo, bar }) => {}); test.afterAll(() => {}); - ` + `, + 'playwright-props.config.ts': ` + const config0: pwt.PlaywrightTestConfig = { + use: { + ignoreHTTPSErrors: undefined, + isMobile: true, + javaScriptEnabled: false, + }, + }; + + const config1: pwt.PlaywrightTestConfig = { + use: { + ignoreHTTPSErrors: undefined, + isMobile: true, + javaScriptEnabled: false, + // @ts-expect-error + hasTouch: 'foo', + }, + }; + + const config2: pwt.PlaywrightTestConfig = { + use: { + ignoreHTTPSErrors: undefined, + isMobile: true, + javaScriptEnabled: false, + // @ts-expect-error + foo: true, + }, + }; + + const config3: pwt.PlaywrightTestConfig<{ foo: boolean }> = { + use: { + ignoreHTTPSErrors: undefined, + isMobile: true, + javaScriptEnabled: false, + foo: true, + }, + }; + + const config4: pwt.PlaywrightTestConfig<{ foo: boolean }> = { + use: { + ignoreHTTPSErrors: undefined, + isMobile: true, + javaScriptEnabled: false, + foo: true, + // @ts-expect-error + hasTouch: 'foo', + }, + }; + `, + + 'playwright-define.config.ts': ` + const config0 = pwt.defineConfig({ + use: { + ignoreHTTPSErrors: undefined, + isMobile: true, + javaScriptEnabled: false, + }, + }); + + const config1 = pwt.defineConfig({ + use: { + ignoreHTTPSErrors: undefined, + isMobile: true, + javaScriptEnabled: false, + // @ts-expect-error + hasTouch: 'foo', + }, + }); + + const config2 = pwt.defineConfig({ + use: { + ignoreHTTPSErrors: undefined, + isMobile: true, + javaScriptEnabled: false, + // @ts-expect-error + foo: true, + }, + }); + + const config3 = pwt.defineConfig<{ foo: boolean }>({ + use: { + ignoreHTTPSErrors: undefined, + isMobile: true, + javaScriptEnabled: false, + foo: true, + }, + }); + + const config4 = pwt.defineConfig<{ foo: boolean }>({ + use: { + ignoreHTTPSErrors: undefined, + isMobile: true, + javaScriptEnabled: false, + foo: true, + // @ts-expect-error + hasTouch: 'foo', + }, + }); + `, }); expect(result.exitCode).toBe(0); }); diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.ts index 43396f6c77..b145a04532 100644 --- a/utils/generate_types/overrides-test.d.ts +++ b/utils/generate_types/overrides-test.d.ts @@ -252,8 +252,13 @@ export interface PlaywrightTestArgs { request: APIRequestContext; } -export type PlaywrightTestProject = Project; -export type PlaywrightTestConfig = Config; +type ExcludeProps = { + [K in Exclude]: A[K]; +}; +type CustomProperties = ExcludeProps; + +export type PlaywrightTestProject = Project, PlaywrightWorkerOptions & CustomProperties>; +export type PlaywrightTestConfig = Config, PlaywrightWorkerOptions & CustomProperties>; import type * as expectType from './expect-types'; import type { Suite } from './testReporter';