Skip to content

Commit

Permalink
feat!: change default return type to unknown instead of any
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Apr 18, 2024
1 parent 11a1f52 commit c0429c2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/runtime/composables/$api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type ApiClientFetchOptions =
Omit<NitroFetchOptions<string>, 'body' | 'cache'>
& {
path?: Record<string, string>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
body?: string | Record<string, any> | FormData | null
}

Expand All @@ -52,7 +53,7 @@ export type OpenAPIClientFetchOptions<
& Omit<NitroFetchOptions<string>, 'query' | 'body' | 'method' | 'cache'>
& SharedFetchOptions

export type ApiClient = <T = any>(
export type ApiClient = <T = unknown>(
path: string,
opts?: ApiClientFetchOptions & SharedFetchOptions,
) => Promise<T>
Expand All @@ -69,7 +70,7 @@ export type OpenAPIClient<Paths> = <
options?: OpenAPIClientFetchOptions<Method, LowercasedMethod, Methods>
) => Promise<ResT>

export function _$api<T = any>(
export function _$api<T = unknown>(
endpointId: string,
path: string,
opts: ApiClientFetchOptions & SharedFetchOptions = {},
Expand Down
7 changes: 5 additions & 2 deletions src/runtime/composables/useApiData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import type { FetchResponseData, FetchResponseError, FilterMethods, ParamsOption
import { useAsyncData, useRequestHeaders, useRuntimeConfig } from '#imports'

type ComputedOptions<T> = {
// eslint-disable-next-line @typescript-eslint/ban-types
[K in keyof T]: T[K] extends Function
? T[K]
// eslint-disable-next-line @typescript-eslint/no-explicit-any
: T[K] extends Record<string, any>
? ComputedOptions<T[K]> | MaybeRef<T[K]>
: MaybeRef<T[K]>;
Expand Down Expand Up @@ -66,10 +68,11 @@ export type UseApiDataOptions<T> = Pick<
| 'timeout'
> & {
path?: MaybeRefOrGetter<Record<string, string>>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
body?: MaybeRef<string | Record<string, any> | FormData | null>
} & SharedAsyncDataOptions<T>

export type UseApiData = <T = any>(
export type UseApiData = <T = unknown>(
path: MaybeRefOrGetter<string>,
opts?: UseApiDataOptions<T>,
) => AsyncData<T | null, NuxtError>
Expand Down Expand Up @@ -103,7 +106,7 @@ export type UseOpenAPIData<Paths> = <
autoKey?: string
) => AsyncData<DataT | null, ErrorT>

export function _useApiData<T = any>(
export function _useApiData<T = unknown>(
endpointId: string,
path: MaybeRefOrGetter<string>,
opts: UseApiDataOptions<T> = {},
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/server/$api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ModuleOptions } from '../../module'
import type { ApiClientFetchOptions } from '../composables/$api'
import { useRuntimeConfig } from '#imports'

export function _$api<T = any>(
export function _$api<T = unknown>(
endpointId: string,
path: string,
opts: ApiClientFetchOptions = {},
Expand Down

0 comments on commit c0429c2

Please sign in to comment.