fix(types): evaluate should not unpack return unions (#29971)
This commit is contained in:
parent
306db80d03
commit
0db1d40abc
2
packages/playwright-core/types/structs.d.ts
vendored
2
packages/playwright-core/types/structs.d.ts
vendored
|
|
@ -40,6 +40,6 @@ export type Unboxed<Arg> =
|
||||||
export type PageFunction0<R> = string | (() => R | Promise<R>);
|
export type PageFunction0<R> = string | (() => R | Promise<R>);
|
||||||
export type PageFunction<Arg, R> = string | ((arg: Unboxed<Arg>) => R | Promise<R>);
|
export type PageFunction<Arg, R> = string | ((arg: Unboxed<Arg>) => R | Promise<R>);
|
||||||
export type PageFunctionOn<On, Arg2, R> = string | ((on: On, arg2: Unboxed<Arg2>) => R | Promise<R>);
|
export type PageFunctionOn<On, Arg2, R> = string | ((on: On, arg2: Unboxed<Arg2>) => R | Promise<R>);
|
||||||
export type SmartHandle<T> = T extends Node ? ElementHandle<T> : JSHandle<T>;
|
export type SmartHandle<T> = [T] extends [Node] ? ElementHandle<T> : JSHandle<T>;
|
||||||
export type ElementHandleForTag<K extends keyof HTMLElementTagNameMap> = ElementHandle<HTMLElementTagNameMap[K]>;
|
export type ElementHandleForTag<K extends keyof HTMLElementTagNameMap> = ElementHandle<HTMLElementTagNameMap[K]>;
|
||||||
export type BindingSource = { context: BrowserContext, page: Page, frame: Frame };
|
export type BindingSource = { context: BrowserContext, page: Page, frame: Frame };
|
||||||
|
|
|
||||||
|
|
@ -323,6 +323,20 @@ playwright.chromium.launch().then(async browser => {
|
||||||
console.log(await resultHandle.jsonValue());
|
console.log(await resultHandle.jsonValue());
|
||||||
await resultHandle.dispose();
|
await resultHandle.dispose();
|
||||||
|
|
||||||
|
// evaluteHandle with two different return types (JSHandle)
|
||||||
|
{
|
||||||
|
const handle = await page.evaluateHandle(() => '' as string | number);
|
||||||
|
const result = await handle.evaluate(value => value);
|
||||||
|
const assertion: AssertType<string | number, typeof result> = true;
|
||||||
|
}
|
||||||
|
// evaluteHandle with two different return types (ElementHandle)
|
||||||
|
{
|
||||||
|
const handle = await page.evaluateHandle(() => '' as any as HTMLInputElement | HTMLTextAreaElement);
|
||||||
|
await handle.evaluate(element => element.value);
|
||||||
|
const assertion: AssertType<playwright.ElementHandle<HTMLInputElement | HTMLTextAreaElement>, typeof handle> = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
await browser.close();
|
await browser.close();
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
@ -606,7 +620,7 @@ playwright.chromium.launch().then(async browser => {
|
||||||
{
|
{
|
||||||
const handle = await page.waitForSelector('*');
|
const handle = await page.waitForSelector('*');
|
||||||
const value = await handle.evaluateHandle((e: HTMLInputElement, x) => e.disabled || x, 123);
|
const value = await handle.evaluateHandle((e: HTMLInputElement, x) => e.disabled || x, 123);
|
||||||
const assertion: AssertType<playwright.JSHandle<boolean> | playwright.JSHandle<number>, typeof value> = true;
|
const assertion: AssertType<playwright.JSHandle<boolean | number>, typeof value> = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue