Skip to content

Commit 47bfc3e

Browse files
committed
chore: clean up types
1 parent 50c5be9 commit 47bfc3e

192 files changed

Lines changed: 768 additions & 1045 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/openapi-ts-angular-common/src/client/client/client.gen.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const createClient = (config: Config = {}): Client => {
8787
opts.headers.delete('Content-Type');
8888
}
8989

90-
const url = buildUrl(opts as any);
90+
const url = buildUrl(opts as Config & RequestOptions);
9191

9292
const req = new HttpRequest<unknown>(opts.method ?? 'GET', url, getValidRequestBody(opts), {
9393
redirect: 'follow',
@@ -141,20 +141,20 @@ export const createClient = (config: Config = {}): Client => {
141141

142142
for (const fn of interceptors.request.fns) {
143143
if (fn) {
144-
req = await fn(req, opts as any);
144+
req = await fn(req, opts as ResolvedRequestOptions);
145145
result.request = req;
146146
}
147147
}
148148

149-
result.response = (await firstValueFrom(
149+
result.response = await firstValueFrom(
150150
opts
151151
.httpClient!.request(req)
152152
.pipe(filter((event) => event.type === HttpEventType.Response)),
153-
)) as HttpResponse<unknown>;
153+
);
154154

155155
for (const fn of interceptors.response.fns) {
156156
if (fn) {
157-
result.response = await fn(result.response, req, opts as any);
157+
result.response = await fn(result.response, req, opts as ResolvedRequestOptions);
158158
}
159159
}
160160

@@ -178,12 +178,12 @@ export const createClient = (config: Config = {}): Client => {
178178

179179
for (const fn of interceptors.error.fns) {
180180
if (fn) {
181-
finalError = (await fn(
181+
finalError = await fn(
182182
finalError,
183183
result.response,
184184
result.request,
185-
options as any,
186-
)) as string;
185+
options as ResolvedRequestOptions,
186+
);
187187
}
188188
}
189189

examples/openapi-ts-angular/src/client/client/client.gen.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export const createClient = (config: Config = {}): Client => {
8787
opts.headers.delete('Content-Type');
8888
}
8989

90-
const url = buildUrl(opts as any);
90+
const url = buildUrl(opts as Config & RequestOptions);
9191

9292
const req = new HttpRequest<unknown>(opts.method ?? 'GET', url, getValidRequestBody(opts), {
9393
redirect: 'follow',
@@ -141,20 +141,20 @@ export const createClient = (config: Config = {}): Client => {
141141

142142
for (const fn of interceptors.request.fns) {
143143
if (fn) {
144-
req = await fn(req, opts as any);
144+
req = await fn(req, opts as ResolvedRequestOptions);
145145
result.request = req;
146146
}
147147
}
148148

149-
result.response = (await firstValueFrom(
149+
result.response = await firstValueFrom(
150150
opts
151151
.httpClient!.request(req)
152152
.pipe(filter((event) => event.type === HttpEventType.Response)),
153-
)) as HttpResponse<unknown>;
153+
);
154154

155155
for (const fn of interceptors.response.fns) {
156156
if (fn) {
157-
result.response = await fn(result.response, req, opts as any);
157+
result.response = await fn(result.response, req, opts as ResolvedRequestOptions);
158158
}
159159
}
160160

@@ -178,12 +178,12 @@ export const createClient = (config: Config = {}): Client => {
178178

179179
for (const fn of interceptors.error.fns) {
180180
if (fn) {
181-
finalError = (await fn(
181+
finalError = await fn(
182182
finalError,
183183
result.response,
184184
result.request,
185-
options as any,
186-
)) as string;
185+
options as ResolvedRequestOptions,
186+
);
187187
}
188188
}
189189

examples/openapi-ts-fastify/src/client/client/client.gen.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ export const createClient = (config: Config = {}): Client => {
204204

205205
for (const fn of interceptors.error.fns) {
206206
if (fn) {
207-
finalError = (await fn(finalError, response, request, options as any)) as unknown;
207+
finalError = await fn(finalError, response, request, options as ResolvedRequestOptions);
208208
}
209209
}
210210

211-
finalError = finalError || ({} as unknown);
211+
finalError = finalError || {};
212212

213213
if (throwOnError) {
214214
throw finalError;
@@ -233,7 +233,6 @@ export const createClient = (config: Config = {}): Client => {
233233
return createSseClient({
234234
...opts,
235235
body: opts.body as BodyInit | null | undefined,
236-
headers: opts.headers as unknown as Record<string, string>,
237236
method,
238237
onRequest: async (url, init) => {
239238
let request = new Request(url, init);

examples/openapi-ts-fetch/src/client/client/client.gen.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ export const createClient = (config: Config = {}): Client => {
204204

205205
for (const fn of interceptors.error.fns) {
206206
if (fn) {
207-
finalError = (await fn(finalError, response, request, options as any)) as unknown;
207+
finalError = await fn(finalError, response, request, options as ResolvedRequestOptions);
208208
}
209209
}
210210

211-
finalError = finalError || ({} as unknown);
211+
finalError = finalError || {};
212212

213213
if (throwOnError) {
214214
throw finalError;
@@ -233,7 +233,6 @@ export const createClient = (config: Config = {}): Client => {
233233
return createSseClient({
234234
...opts,
235235
body: opts.body as BodyInit | null | undefined,
236-
headers: opts.headers as unknown as Record<string, string>,
237236
method,
238237
onRequest: async (url, init) => {
239238
let request = new Request(url, init);

examples/openapi-ts-ky/src/client/client/client.gen.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export const createClient = (config: Config = {}): Client => {
155155
};
156156

157157
request = new Request(url, {
158-
body: kyOptions.body as BodyInit,
158+
body: kyOptions.body,
159159
headers: kyOptions.headers as HeadersInit,
160160
method: kyOptions.method,
161161
});
@@ -288,12 +288,7 @@ export const createClient = (config: Config = {}): Client => {
288288
// parseErrorResponse already ran interceptors and threw (throwOnError=true); just re-throw
289289
for (const fn of interceptors.error.fns) {
290290
if (fn) {
291-
finalError = (await fn(
292-
finalError,
293-
response as any,
294-
request as any,
295-
options as any,
296-
)) as string;
291+
finalError = await fn(finalError, response, request, options as ResolvedRequestOptions);
297292
}
298293
}
299294

@@ -323,7 +318,6 @@ export const createClient = (config: Config = {}): Client => {
323318
...opts,
324319
body: opts.body as BodyInit | null | undefined,
325320
fetch: globalThis.fetch,
326-
headers: opts.headers as unknown as Record<string, string>,
327321
method,
328322
onRequest: async (url, init) => {
329323
let request = new Request(url, init);

examples/openapi-ts-nestjs/src/client/client/client.gen.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ export const createClient = (config: Config = {}): Client => {
204204

205205
for (const fn of interceptors.error.fns) {
206206
if (fn) {
207-
finalError = (await fn(finalError, response, request, options as any)) as unknown;
207+
finalError = await fn(finalError, response, request, options as ResolvedRequestOptions);
208208
}
209209
}
210210

211-
finalError = finalError || ({} as unknown);
211+
finalError = finalError || {};
212212

213213
if (throwOnError) {
214214
throw finalError;
@@ -233,7 +233,6 @@ export const createClient = (config: Config = {}): Client => {
233233
return createSseClient({
234234
...opts,
235235
body: opts.body as BodyInit | null | undefined,
236-
headers: opts.headers as unknown as Record<string, string>,
237236
method,
238237
onRequest: async (url, init) => {
239238
let request = new Request(url, init);

examples/openapi-ts-next/src/client/client/client.gen.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ export const createClient = (config: Config = {}): Client => {
191191

192192
for (const fn of interceptors.error.fns) {
193193
if (fn) {
194-
finalError = (await fn(finalError, response, options as any)) as unknown;
194+
finalError = await fn(finalError, response, options as ResolvedRequestOptions);
195195
}
196196
}
197197

198-
finalError = finalError || ({} as unknown);
198+
finalError = finalError || {};
199199

200200
if (throwOnError) {
201201
throw finalError;
@@ -216,18 +216,13 @@ export const createClient = (config: Config = {}): Client => {
216216
return createSseClient({
217217
...opts,
218218
body: opts.body as BodyInit | null | undefined,
219-
headers: opts.headers as unknown as Record<string, string>,
220219
method,
221220
onRequest: async (url, init) => {
222221
let request = new Request(url, init);
223-
const requestInit = {
224-
...init,
225-
method: init.method as Config['method'],
226-
url,
227-
};
222+
const requestInit = { ...init, url };
228223
for (const fn of interceptors.request.fns) {
229224
if (fn) {
230-
await fn(requestInit as unknown as ResolvedRequestOptions);
225+
await fn(requestInit as ResolvedRequestOptions);
231226
request = new Request(requestInit.url, requestInit);
232227
}
233228
}

examples/openapi-ts-ofetch/src/client/client/client.gen.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export const createClient = (config: Config = {}): Client => {
118118
// ignore request.body changes to avoid turning serialized bodies into streams
119119
// body comes only from getValidRequestBody(options)
120120
// reflect signal if present
121-
opts.signal = (request as any).signal as AbortSignal | undefined;
121+
opts.signal = request.signal;
122122

123123
// When body is FormData, remove Content-Type header to avoid boundary mismatch.
124124
// Note: We already delete Content-Type in resolveOptions for FormData, but the
@@ -140,19 +140,23 @@ export const createClient = (config: Config = {}): Client => {
140140
body: BodyInit | null | undefined,
141141
responseType: OfetchResponseType | undefined,
142142
) => {
143-
const effectiveRetry = isRepeatableBody(body) ? (opts.retry as any) : (0 as any);
143+
const effectiveRetry = isRepeatableBody(body) ? opts.retry : 0;
144144
return buildOfetchOptions(opts, body, responseType, effectiveRetry);
145145
};
146146

147147
const request: Client['request'] = async (options) => {
148-
const throwOnError = (options as any).throwOnError ?? _config.throwOnError;
149-
const responseStyle = (options as any).responseStyle ?? _config.responseStyle;
148+
const throwOnError = options.throwOnError ?? _config.throwOnError;
149+
const responseStyle = options.responseStyle ?? _config.responseStyle;
150150

151151
let request: Request | undefined;
152152
let response: Awaited<ReturnType<typeof ofetch.raw>> | undefined;
153153

154154
try {
155-
const { networkBody: initialNetworkBody, opts, url } = await resolveOptions(options as any);
155+
const {
156+
networkBody: initialNetworkBody,
157+
opts,
158+
url,
159+
} = await resolveOptions(options as RequestOptions);
156160
// map parseAs -> ofetch responseType once per request
157161
const ofetchResponseType: OfetchResponseType | undefined = mapParseAsToResponseType(
158162
opts.parseAs,
@@ -165,7 +169,7 @@ export const createClient = (config: Config = {}): Client => {
165169
const networkBody = initialNetworkBody;
166170
const requestInit: ReqInit = {
167171
body: networkBody,
168-
headers: opts.headers as Headers,
172+
headers: opts.headers,
169173
method: opts.method,
170174
redirect: 'follow',
171175
signal: opts.signal,
@@ -176,11 +180,7 @@ export const createClient = (config: Config = {}): Client => {
176180
const finalUrl = request.url;
177181

178182
// build ofetch options and perform the request (.raw keeps the Response)
179-
const responseOptions = buildNetworkOptions(
180-
opts as ResolvedRequestOptions,
181-
networkBody,
182-
ofetchResponseType,
183-
);
183+
const responseOptions = buildNetworkOptions(opts, networkBody, ofetchResponseType);
184184

185185
response = await $ofetch.raw(finalUrl, responseOptions);
186186

@@ -203,12 +203,12 @@ export const createClient = (config: Config = {}): Client => {
203203

204204
for (const fn of interceptors.error.fns) {
205205
if (fn) {
206-
finalError = await fn(finalError, response, request, options as any);
206+
finalError = await fn(finalError, response, request, options as ResolvedRequestOptions);
207207
}
208208
}
209209

210210
// ensure error is never undefined after interceptors
211-
finalError = (finalError as any) || ({} as string);
211+
finalError = finalError || ({} as string);
212212

213213
if (throwOnError) {
214214
throw finalError;
@@ -219,23 +219,23 @@ export const createClient = (config: Config = {}): Client => {
219219
};
220220

221221
const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
222-
request({ ...options, method } as any);
222+
request({ ...options, method });
223223

224224
const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
225225
const { networkBody, opts, url } = await resolveOptions(options);
226-
const optsForSse: any = { ...opts };
226+
const optsForSse = { ...opts };
227227
delete optsForSse.body; // body is provided via serializedBody below
228228
return createSseClient({
229-
...optsForSse,
229+
...(optsForSse as Omit<typeof opts, 'body'>),
230230
fetch: opts.fetch,
231-
headers: opts.headers as Headers,
231+
headers: opts.headers,
232232
method,
233233
onRequest: async (url, init) => {
234234
let request = new Request(url, init);
235235
request = await applyRequestInterceptors(request, opts, networkBody);
236236
return request;
237237
},
238-
serializedBody: networkBody as BodyInit | null | undefined,
238+
serializedBody: networkBody,
239239
signal: opts.signal,
240240
url,
241241
});

examples/openapi-ts-openai/src/client/client/client.gen.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ export const createClient = (config: Config = {}): Client => {
204204

205205
for (const fn of interceptors.error.fns) {
206206
if (fn) {
207-
finalError = (await fn(finalError, response, request, options as any)) as unknown;
207+
finalError = await fn(finalError, response, request, options as ResolvedRequestOptions);
208208
}
209209
}
210210

211-
finalError = finalError || ({} as unknown);
211+
finalError = finalError || {};
212212

213213
if (throwOnError) {
214214
throw finalError;
@@ -233,7 +233,6 @@ export const createClient = (config: Config = {}): Client => {
233233
return createSseClient({
234234
...opts,
235235
body: opts.body as BodyInit | null | undefined,
236-
headers: opts.headers as unknown as Record<string, string>,
237236
method,
238237
onRequest: async (url, init) => {
239238
let request = new Request(url, init);

examples/openapi-ts-pinia-colada/src/client/client/client.gen.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,11 @@ export const createClient = (config: Config = {}): Client => {
204204

205205
for (const fn of interceptors.error.fns) {
206206
if (fn) {
207-
finalError = (await fn(finalError, response, request, options as any)) as unknown;
207+
finalError = await fn(finalError, response, request, options as ResolvedRequestOptions);
208208
}
209209
}
210210

211-
finalError = finalError || ({} as unknown);
211+
finalError = finalError || {};
212212

213213
if (throwOnError) {
214214
throw finalError;
@@ -233,7 +233,6 @@ export const createClient = (config: Config = {}): Client => {
233233
return createSseClient({
234234
...opts,
235235
body: opts.body as BodyInit | null | undefined,
236-
headers: opts.headers as unknown as Record<string, string>,
237236
method,
238237
onRequest: async (url, init) => {
239238
let request = new Request(url, init);

0 commit comments

Comments
 (0)