feat(fetch/network): add generic to json method (#34091)
This commit is contained in:
parent
9c14cccc24
commit
94ffbcb9c5
|
|
@ -350,9 +350,9 @@ export class APIResponse implements api.APIResponse {
|
||||||
return content.toString('utf8');
|
return content.toString('utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
async json(): Promise<object> {
|
async json<T = object>(): Promise<T> {
|
||||||
const content = await this.text();
|
const content = await this.text();
|
||||||
return JSON.parse(content);
|
return JSON.parse(content) as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
async [Symbol.asyncDispose]() {
|
async [Symbol.asyncDispose]() {
|
||||||
|
|
|
||||||
|
|
@ -718,9 +718,9 @@ export class Response extends ChannelOwner<channels.ResponseChannel> implements
|
||||||
return content.toString('utf8');
|
return content.toString('utf8');
|
||||||
}
|
}
|
||||||
|
|
||||||
async json(): Promise<object> {
|
async json<T = object>(): Promise<T> {
|
||||||
const content = await this.text();
|
const content = await this.text();
|
||||||
return JSON.parse(content);
|
return JSON.parse(content) as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
request(): Request {
|
request(): Request {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue