Skip to content

Commit

Permalink
chore(client): use native extends instead of Override to fix type…
Browse files Browse the repository at this point in the history
… inference issues

Refactored the `ClientOptions` and `RequestOptions` types to use native TypeScript `extends` instead of the custom `Override` utility. This change improves type inference and compatibility within TypeScript environments, eliminating issues previously encountered with complex type definitions. The removal of `Override` simplifies the type structure and enhances maintainability.
  • Loading branch information
shorwood committed Nov 26, 2024
1 parent 4dd9a24 commit 0b1ba02
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/client/createClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MaybeLiteral, Override, Pretty } from '@unshared/types'
import type { MaybeLiteral, Pretty } from '@unshared/types'
import type { OpenAPI, OpenAPIV2 as V2, OpenAPIV3 as V3, OpenAPIV3_1 as V3_1 } from 'openapi-types'
import type { OpenAPIV2, OpenAPIV3 } from './openapi/index'
import type { RequestHooks } from './utils/handleResponse'
Expand Down Expand Up @@ -34,7 +34,7 @@ export type Client<T = OpenAPI.Document> =
& { fetch: ClientFetch<T> }
>

export type ClientOptions<T = any> = Override<RequestHooks & RequestOptions, {
export interface ClientOptions<T = any> extends Omit<RequestOptions, 'headers'>, RequestHooks {
baseUrl?: ClientBaseUrl<T>

/**
Expand All @@ -45,7 +45,7 @@ export type ClientOptions<T = any> = Override<RequestHooks & RequestOptions, {
headers?: T extends V3.Document
? OpenAPIV3.ServerHeaders<T>
: never
}>
}

/**
* Create a new client instance for the given OpenAPI specification.
Expand Down
5 changes: 2 additions & 3 deletions packages/client/utils/parseRequest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable unicorn/prevent-abbreviations */
import type { MaybeLiteral } from '@unshared/types'
import type { Override } from '@unshared/types'
import type { HttpHeader, HttpMethod } from '../types'
import type { SearchArrayFormat, SearchParamsObject } from './toSearchParams'
import { parseRequestBody } from './parseRequestBody'
Expand All @@ -19,7 +18,7 @@ export type RequestHeaders = Partial<Record<MaybeLiteral<HttpHeader>, string>>
export type RequestBody = File | FormData | ReadableStream | Record<string, unknown> | string

/** Options to pass to the request. */
export type RequestOptions = Override<RequestInit, {
export interface RequestOptions extends Omit<RequestInit, 'body' | 'headers'> {

/**
* The method to use for the request.
Expand Down Expand Up @@ -67,7 +66,7 @@ export type RequestOptions = Override<RequestInit, {
* The path parameters to include in the request.
*/
parameters?: Record<string, number | string>
}>
}

export interface RequestContext {
url?: URL
Expand Down

0 comments on commit 0b1ba02

Please sign in to comment.