You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Simplify declaration of ResponseType (#4926)
Currently, this is looking for a `json` property on `IHttpOpts`. There is no such property, so that part of the declaration is completely redundant, and we may as well remove it. I looked into making it check `IRequestOpts`, which *does* have a `json` property, but couldn't make it work. Also add some docs, while we're there.
This commit is contained in:
committed by
GitHub
parent
32509d1fd1
commit
1a58ce4649
@@ -37,11 +37,17 @@ interface TypedResponse<T> extends Response {
|
|||||||
json(): Promise<T>;
|
json(): Promise<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ResponseType<T, O extends IHttpOpts> = O extends { json: false }
|
/**
|
||||||
? string
|
* The type returned by {@link FetchHttpApi.request}, etc.
|
||||||
: O extends { onlyData: true } | undefined
|
*
|
||||||
? T
|
* If {@link IHttpOpts.onlyData} is unset or false, then the request methods return a
|
||||||
: TypedResponse<T>;
|
* {@link https://developer.mozilla.org/en-US/docs/Web/API/Response Response} object,
|
||||||
|
* which we abstract via `TypedResponse`. Otherwise, we just cast it to `T`.
|
||||||
|
*
|
||||||
|
* @typeParam T - The type (specified by the application on the request method) that we will cast the response to.
|
||||||
|
* @typeParam O - The type of the options object on the {@link FetchHttpApi} instance.
|
||||||
|
*/
|
||||||
|
export type ResponseType<T, O extends IHttpOpts> = O extends { onlyData: true } | undefined ? T : TypedResponse<T>;
|
||||||
|
|
||||||
export class FetchHttpApi<O extends IHttpOpts> {
|
export class FetchHttpApi<O extends IHttpOpts> {
|
||||||
private abortController = new AbortController();
|
private abortController = new AbortController();
|
||||||
|
|||||||
Reference in New Issue
Block a user