Skip to content

Commit

Permalink
feat: add generic to json method
Browse files Browse the repository at this point in the history
added the ability to specify the json type during parsing
  • Loading branch information
mmtv-qa committed Dec 19, 2024
1 parent a239ab3 commit 00b05c0
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 00b05c0

Please sign in to comment.