Skip to content

Commit

Permalink
feat(fetch/network): add generic to json method (#34091)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmtv-qa authored Dec 19, 2024
1 parent 9c14ccc commit 94ffbcb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/playwright-core/src/client/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ export class APIResponse implements api.APIResponse {
return content.toString('utf8');
}

async json(): Promise<object> {
async json<T = object>(): Promise<T> {
const content = await this.text();
return JSON.parse(content);
return JSON.parse(content) as T;
}

async [Symbol.asyncDispose]() {
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/src/client/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,9 @@ export class Response extends ChannelOwner<channels.ResponseChannel> implements
return content.toString('utf8');
}

async json(): Promise<object> {
async json<T = object>(): Promise<T> {
const content = await this.text();
return JSON.parse(content);
return JSON.parse(content) as T;
}

request(): Request {
Expand Down

0 comments on commit 94ffbcb

Please sign in to comment.