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

View File

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

View File

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