feat(fetch/network): add generic to json method (#34091)

This commit is contained in:
Volodymyr Momot 2024-12-19 20:36:02 +02:00 committed by GitHub
parent 9c14cccc24
commit 94ffbcb9c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View File

@ -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]() {

View File

@ -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 {