fix(types): fixed Fixtures type to disambiguite between intersected mapped types

This commit is contained in:
Mateusz Burzyński 2024-11-27 14:42:00 +01:00
parent f3ae940684
commit c4fd612bc3
3 changed files with 67 additions and 4 deletions

View file

@ -5663,9 +5663,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 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 keyof W]?: [WorkerFixtureValue<W[K], W & PW>, { scope: 'worker', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }]; [K in keyof W as Exclude<K, keyof PW | keyof PT>]?: [WorkerFixtureValue<W[K], W & PW>, { scope: 'worker', 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 }]; [K in keyof T as Exclude<K, keyof PW | 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 }];
}; };
type BrowserName = 'chromium' | 'firefox' | 'webkit'; type BrowserName = 'chromium' | 'firefox' | 'webkit';

View file

@ -17,3 +17,66 @@ test('sample test', async ({ page, plugin }) => {
// @ts-expect-error // @ts-expect-error
await expect(page).toContainText(123); await expect(page).toContainText(123);
}); });
test1.extend({
page: async ({ page }) => {
type IsPage = (typeof page) extends Page ? true : never;
const isPage: IsPage = true;
},
});
test1.extend<{ myFixture: (arg: number) => void }>({
page: async ({ page }) => {
type IsPage = (typeof page) extends Page ? true : never;
const isPage: IsPage = true;
},
});
test1.extend({
myFixture: async ({ page }) => {
type IsPage = (typeof page) extends Page ? true : never;
const isPage: IsPage = true;
}
});
test1.extend<{ myFixture: (arg: number) => void }>({
myFixture: async ({ page }) => {
type IsPage = (typeof page) extends Page ? true : never;
const isPage: IsPage = true;
}
});
test1.extend({
page: async ({ page }) => {
type IsPage = (typeof page) extends Page ? true : never;
const isPage: IsPage = true;
},
myFixture: async ({ page }) => {
type IsPage = (typeof page) extends Page ? true : never;
const isPage: IsPage = true;
}
});
test1.extend<{ myFixture: (arg: number) => void }>({
page: async ({ page }) => {
type IsPage = (typeof page) extends Page ? true : never;
const isPage: IsPage = true;
},
myFixture: async ({ page }) => {
type IsPage = (typeof page) extends Page ? true : never;
const isPage: IsPage = true;
}
});
test1.extend<{ myFixture: (arg: number) => void }>({
// @ts-expect-error
myFixture: (arg: number) => {},
});
test1.extend<{ myFixture: (arg: number) => void }>({
myFixture: async (_, use) => {
use((arg: number) => {});
// @ts-expect-error
use((arg: string) => {});
}
});

View file

@ -178,9 +178,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 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 keyof W]?: [WorkerFixtureValue<W[K], W & PW>, { scope: 'worker', auto?: boolean, option?: boolean, timeout?: number | undefined, title?: string, box?: boolean }]; [K in keyof W as Exclude<K, keyof PW | keyof PT>]?: [WorkerFixtureValue<W[K], W & PW>, { scope: 'worker', 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 }]; [K in keyof T as Exclude<K, keyof PW | 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 }];
}; };
type BrowserName = 'chromium' | 'firefox' | 'webkit'; type BrowserName = 'chromium' | 'firefox' | 'webkit';