feat: add generic to json method

added the ability to specify the json type during parsing
This commit is contained in:
Volodymyr Momot 2024-12-19 16:57:38 +02:00
parent a239ab3048
commit 00b05c0a5e
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'); 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]() {

View file

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