fix(types): update PlaywrightTestConfig types (#20540)

This makes errors more focused on the custom properties.

References #20416.
This commit is contained in:
Dmitry Gozman 2023-01-31 15:02:01 -08:00 committed by GitHub
parent cc5c4ae3e2
commit 9c6c31a442
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 114 additions and 5 deletions

View file

@ -3724,8 +3724,13 @@ export interface PlaywrightTestArgs {
request: APIRequestContext;
}
export type PlaywrightTestProject<TestArgs = {}, WorkerArgs = {}> = Project<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>;
export type PlaywrightTestConfig<TestArgs = {}, WorkerArgs = {}> = Config<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>;
type ExcludeProps<A, B> = {
[K in Exclude<keyof A, keyof B>]: A[K];
};
type CustomProperties<T> = ExcludeProps<T, PlaywrightTestOptions & PlaywrightWorkerOptions & PlaywrightTestArgs & PlaywrightWorkerArgs>;
export type PlaywrightTestProject<TestArgs = {}, WorkerArgs = {}> = Project<PlaywrightTestOptions & CustomProperties<TestArgs>, PlaywrightWorkerOptions & CustomProperties<WorkerArgs>>;
export type PlaywrightTestConfig<TestArgs = {}, WorkerArgs = {}> = Config<PlaywrightTestOptions & CustomProperties<TestArgs>, PlaywrightWorkerOptions & CustomProperties<WorkerArgs>>;
import type * as expectType from './expect-types';
import type { Suite } from './testReporter';

View file

@ -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);
});

View file

@ -252,8 +252,13 @@ export interface PlaywrightTestArgs {
request: APIRequestContext;
}
export type PlaywrightTestProject<TestArgs = {}, WorkerArgs = {}> = Project<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>;
export type PlaywrightTestConfig<TestArgs = {}, WorkerArgs = {}> = Config<PlaywrightTestOptions & TestArgs, PlaywrightWorkerOptions & WorkerArgs>;
type ExcludeProps<A, B> = {
[K in Exclude<keyof A, keyof B>]: A[K];
};
type CustomProperties<T> = ExcludeProps<T, PlaywrightTestOptions & PlaywrightWorkerOptions & PlaywrightTestArgs & PlaywrightWorkerArgs>;
export type PlaywrightTestProject<TestArgs = {}, WorkerArgs = {}> = Project<PlaywrightTestOptions & CustomProperties<TestArgs>, PlaywrightWorkerOptions & CustomProperties<WorkerArgs>>;
export type PlaywrightTestConfig<TestArgs = {}, WorkerArgs = {}> = Config<PlaywrightTestOptions & CustomProperties<TestArgs>, PlaywrightWorkerOptions & CustomProperties<WorkerArgs>>;
import type * as expectType from './expect-types';
import type { Suite } from './testReporter';