update ts samples

This commit is contained in:
William Cheng 2022-12-23 01:17:31 +08:00
parent 71a7a822f4
commit 625a7233e2
2 changed files with 14 additions and 14 deletions

View File

@ -146,22 +146,22 @@ export class BaseAPI {
credentials: this.configuration.credentials, credentials: this.configuration.credentials,
}; };
const overridedInit: RequestInit = { const overriddenInit: RequestInit = {
...initParams, ...initParams,
...(await initOverrideFn({ ...(await initOverrideFn({
init: initParams, init: initParams,
context, context,
})) }))
} };
const init: RequestInit = { const init: RequestInit = {
...overridedInit, ...overriddenInit,
body: body:
isFormData(overridedInit.body) || isFormData(overriddenInit.body) ||
overridedInit.body instanceof URLSearchParams || overriddenInit.body instanceof URLSearchParams ||
isBlob(overridedInit.body) isBlob(overriddenInit.body)
? overridedInit.body ? overriddenInit.body
: JSON.stringify(overridedInit.body), : JSON.stringify(overriddenInit.body),
}; };
return { url, init }; return { url, init };
@ -177,7 +177,7 @@ export class BaseAPI {
}) || fetchParams; }) || fetchParams;
} }
} }
let response = undefined; let response: Response | undefined = undefined;
try { try {
response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init); response = await (this.configuration.fetchApi || fetch)(fetchParams.url, fetchParams.init);
} catch (e) { } catch (e) {
@ -226,11 +226,11 @@ export class BaseAPI {
}; };
function isBlob(value: any): value is Blob { function isBlob(value: any): value is Blob {
return typeof Blob !== 'undefined' && value instanceof Blob return typeof Blob !== 'undefined' && value instanceof Blob;
} }
function isFormData(value: any): value is FormData { function isFormData(value: any): value is FormData {
return typeof FormData !== "undefined" && value instanceof FormData return typeof FormData !== "undefined" && value instanceof FormData;
} }
export class ResponseError extends Error { export class ResponseError extends Error {
@ -268,7 +268,7 @@ export type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS'
export type HTTPHeaders = { [key: string]: string }; export type HTTPHeaders = { [key: string]: string };
export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery }; export type HTTPQuery = { [key: string]: string | number | null | boolean | Array<string | number | null | boolean> | Set<string | number | null | boolean> | HTTPQuery };
export type HTTPBody = Json | FormData | URLSearchParams; export type HTTPBody = Json | FormData | URLSearchParams;
export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody } export type HTTPRequestInit = { headers?: HTTPHeaders; method: HTTPMethod; credentials?: RequestCredentials; body?: HTTPBody };
export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original'; export type ModelPropertyNaming = 'camelCase' | 'snake_case' | 'PascalCase' | 'original';
export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise<RequestInit> export type InitOverrideFunction = (requestContext: { init: HTTPRequestInit, context: RequestOpts }) => Promise<RequestInit>
@ -335,7 +335,7 @@ export function canConsumeForm(consumes: Consume[]): boolean {
} }
export interface Consume { export interface Consume {
contentType: string contentType: string;
} }
export interface RequestContext { export interface RequestContext {