fix: make fetchjson returntype generic (#2082)

This commit is contained in:
Pascal Schilp 2023-09-26 08:53:07 +02:00 committed by GitHub
parent a447ad66a1
commit 0952647d95
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/ajax': minor
---
make return type for `fetchJson` generic

View file

@ -175,9 +175,10 @@ export class Ajax {
* - Deserializing response payload as JSON
* - Adding the correct Content-Type and Accept headers
*
* @template T
* @param {RequestInfo} info
* @param {LionRequestInit} [init]
* @returns {Promise<{ response: Response, body: string|Object }>}
* @returns {Promise<{ response: Response, body: string | T }>}
*/
async fetchJson(info, init) {
const lionInit = {
@ -204,8 +205,9 @@ export class Ajax {
}
/**
* @template T
* @param {Response} response
* @returns {Promise<string|Object>}
* @returns {Promise<string|T>}
*/
async __parseBody(response) {
// clone the response, so the consumer can also read it out manually as well