diff --git a/.changeset/early-steaks-attend.md b/.changeset/early-steaks-attend.md new file mode 100644 index 000000000..b36c21cc5 --- /dev/null +++ b/.changeset/early-steaks-attend.md @@ -0,0 +1,5 @@ +--- +'@lion/ajax': minor +--- + +make return type for `fetchJson` generic diff --git a/packages/ajax/src/Ajax.js b/packages/ajax/src/Ajax.js index 4f84d66eb..5831524b6 100644 --- a/packages/ajax/src/Ajax.js +++ b/packages/ajax/src/Ajax.js @@ -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} + * @returns {Promise} */ async __parseBody(response) { // clone the response, so the consumer can also read it out manually as well