Fix types

This commit is contained in:
Andrew Kingston 2024-12-03 11:02:31 +00:00
parent b546512a2f
commit 86c34cc549
No known key found for this signature in database
3 changed files with 11 additions and 9 deletions

View File

@ -108,7 +108,7 @@ export const createAPIClient = (config: APIClientConfig = {}): APIClient => {
}
// Performs an API call to the server.
const makeApiCall = async <RequestT, ResponseT>(
const makeApiCall = async <RequestT = null, ResponseT = void>(
callConfig: APICallConfig<RequestT, ResponseT>
): Promise<ResponseT> => {
let { json, method, external, body, url, parseResponse, suppressErrors } =
@ -131,7 +131,7 @@ export const createAPIClient = (config: APIClientConfig = {}): APIClient => {
}
// Build request body
let requestBody: RequestT | string = body
let requestBody: any = body
if (json) {
try {
requestBody = JSON.stringify(body)
@ -146,7 +146,7 @@ export const createAPIClient = (config: APIClientConfig = {}): APIClient => {
response = await fetch(url, {
method,
headers,
body: requestBody as any,
body: requestBody,
credentials: "same-origin",
})
} catch (error) {
@ -187,7 +187,7 @@ export const createAPIClient = (config: APIClientConfig = {}): APIClient => {
// Performs an API call to the server and caches the response.
// Future invocation for this URL will return the cached result instead of
// hitting the server again.
const makeCachedApiCall = async <RequestT = void, ResponseT = void>(
const makeCachedApiCall = async <RequestT = null, ResponseT = void>(
callConfig: APICallConfig<RequestT, ResponseT>
): Promise<ResponseT> => {
const identifier = callConfig.url
@ -201,7 +201,7 @@ export const createAPIClient = (config: APIClientConfig = {}): APIClient => {
// Constructs an API call function for a particular HTTP method
const requestApiCall =
(method: HTTPMethod) =>
async <RequestT = void, ResponseT = void>(
async <RequestT = null, ResponseT = void>(
params: APICallParams<RequestT, ResponseT>
): Promise<ResponseT> => {
try {
@ -211,7 +211,6 @@ export const createAPIClient = (config: APIClientConfig = {}): APIClient => {
suppressErrors: false,
cache: false,
method,
body: params.body,
...params,
}
let { url, cache, external } = callConfig

View File

@ -42,14 +42,14 @@ export type APIClientConfig = {
onMigrationDetected?: (migration: string) => void
}
export type APICallConfig<RequestT = null, ResponseT = void> = {
export type APICallConfig<RequestT, ResponseT> = {
method: HTTPMethod
url: string
body: RequestT
json: boolean
external: boolean
suppressErrors: boolean
cache: boolean
body?: RequestT
parseResponse?: (response: Response) => Promise<ResponseT> | ResponseT
}

View File

@ -2,10 +2,13 @@
"compilerOptions": {
"target": "ESNext",
"moduleResolution": "bundler",
"skipLibCheck": true,
"paths": {
"@budibase/types": ["../types/src"],
"@budibase/shared-core": ["../shared-core/src"],
"@budibase/bbui": ["../bbui/src"]
}
}
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist"]
}