Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix: make Serializable type any (#9059)

Max Schmitt89aace688f1f
diff --git a/docs/src/api/class-request.md b/docs/src/api/class-request.md
index 76af6f90aa..d414f00954 100644
--- a/docs/src/api/class-request.md
+++ b/docs/src/api/class-request.md
@@ -102,7 +102,7 @@ Request's post body in a binary form, if any.
## method: Request.postDataJSON
* langs: js, python
-- returns: <[null]|[any]>
+- returns: <[null]|[Serializable]>
Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.
diff --git a/types/structs.d.ts b/types/structs.d.ts
index c55ef43a0b..50232b91df 100644
--- a/types/structs.d.ts
+++ b/types/structs.d.ts
@@ -19,7 +19,7 @@ import { JSHandle, ElementHandle, Frame, Page, BrowserContext, Locator } from '.
/**
* Can be converted to JSON
*/
-export type Serializable = {};
+export type Serializable = any;
/**
* Can be converted to JSON, but may also contain JSHandles.
*/
diff --git a/types/types.d.ts b/types/types.d.ts
index 8ca2d97689..2d7909680b 100644
--- a/types/types.d.ts
+++ b/types/types.d.ts
@@ -13420,7 +13420,7 @@ export interface Request {
* When the response is `application/x-www-form-urlencoded` then a key/value object of the values will be returned.
* Otherwise it will be parsed as JSON.
*/
- postDataJSON(): null|any;
+ postDataJSON(): null|Serializable;
/**
* Request that was redirected by the server to this one, if any.
diff --git a/utils/generate_types/test/test.ts b/utils/generate_types/test/test.ts
index 66fd88a977..13766f939c 100644
--- a/utils/generate_types/test/test.ts
+++ b/utils/generate_types/test/test.ts
@@ -793,10 +793,11 @@ playwright.chromium.launch().then(async browser => {
(async () => {
const browser = await playwright.chromium.launch();
const page = await browser.newPage();
- await Promise.all([
+ const [response] = await Promise.all([
page.waitForResponse(response => response.url().includes('example.com')),
page.goto('https://example.com')
]);
+ console.log((await response!.json()).foobar); // JSON return value should be any
await browser.close();
})();