From c4d97e1c34e285959e19d423fb634beebad0a535 Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Fri, 22 Sep 2023 17:21:19 +0530 Subject: [PATCH] request: fix/improve typesafety of `TData` --- src/Utils/request/request.ts | 4 ++-- src/Utils/request/useQuery.ts | 6 +++--- src/Utils/request/utils.ts | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Utils/request/request.ts b/src/Utils/request/request.ts index 45c8e5ce664..c946f524ab9 100644 --- a/src/Utils/request/request.ts +++ b/src/Utils/request/request.ts @@ -2,7 +2,7 @@ import handleResponse from "./handleResponse"; import { RequestOptions, RequestResult, Route } from "./types"; import { makeHeaders, makeUrl } from "./utils"; -interface Options extends RequestOptions { +interface Options extends RequestOptions { controller?: AbortController; } @@ -16,7 +16,7 @@ export default async function request( onResponse, silent, reattempts = 3, - }: Options = {} + }: Options = {} ): Promise> { const signal = controller?.signal; const url = makeUrl(path, query, pathParams); diff --git a/src/Utils/request/useQuery.ts b/src/Utils/request/useQuery.ts index a370b909fe9..2a8cb2e2ad4 100644 --- a/src/Utils/request/useQuery.ts +++ b/src/Utils/request/useQuery.ts @@ -3,14 +3,14 @@ import { QueryRoute, RequestOptions, RequestResult } from "./types"; import request from "./request"; import { mergeRequestOptions } from "./utils"; -export interface QueryOptions extends RequestOptions { +export interface QueryOptions extends RequestOptions { prefetch?: boolean; refetchOnWindowFocus?: boolean; } export default function useQuery( route: QueryRoute, - options?: QueryOptions + options?: QueryOptions ) { const [response, setResponse] = useState>(); const [loading, setLoading] = useState(false); @@ -18,7 +18,7 @@ export default function useQuery( const controllerRef = useRef(); const runQuery = useCallback( - async (overrides?: QueryOptions) => { + async (overrides?: QueryOptions) => { controllerRef.current?.abort(); const controller = new AbortController(); diff --git a/src/Utils/request/utils.ts b/src/Utils/request/utils.ts index 5a4fb7e2b2e..f159df1b7a7 100644 --- a/src/Utils/request/utils.ts +++ b/src/Utils/request/utils.ts @@ -69,10 +69,10 @@ export function getAuthorizationHeader() { return null; } -export function mergeRequestOptions( - options: RequestOptions, - overrides: RequestOptions -): RequestOptions { +export function mergeRequestOptions( + options: RequestOptions, + overrides: RequestOptions +): RequestOptions { return { ...options, ...overrides,