Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

732 reduce amount of used generics #735

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
}

return (
<Function export name={name} generics={generics} returnType={returnType} params={params} JSDoc={JSDoc}>
<Function export name={name} returnType={returnType} params={params} JSDoc={JSDoc}>

Check warning on line 101 in packages/swagger-tanstack-query/src/components/Mutation.tsx

View check run for this annotation

Codecov / codecov/patch

packages/swagger-tanstack-query/src/components/Mutation.tsx#L101

Added line #L101 was not covered by tests
{`
const { mutation: mutationOptions, client: clientOptions = {} } = options ?? {}

Expand Down
12 changes: 2 additions & 10 deletions packages/swagger-tanstack-query/src/components/Query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
if (isV5) {
return (
<>
<Function name={name} export generics={generics} returnType={resolvedReturnType} params={params} JSDoc={JSDoc}>
<Function name={name} export returnType={resolvedReturnType} params={params} JSDoc={JSDoc}>

Check warning on line 65 in packages/swagger-tanstack-query/src/components/Query.tsx

View check run for this annotation

Codecov / codecov/patch

packages/swagger-tanstack-query/src/components/Query.tsx#L65

Added line #L65 was not covered by tests
{`
const { query: queryOptions, client: clientOptions = {} } = options ?? {}
const queryKey = queryOptions?.queryKey ?? ${hook.queryKey}
Expand All @@ -85,7 +85,7 @@

return (
<>
<Function name={name} export generics={generics} returnType={resolvedReturnType} params={params} JSDoc={JSDoc}>
<Function name={name} export returnType={resolvedReturnType} params={params} JSDoc={JSDoc}>
{`
const { query: queryOptions, client: clientOptions = {} } = options ?? {}
const queryKey = queryOptions?.queryKey ?? ${hook.queryKey}
Expand Down Expand Up @@ -302,7 +302,6 @@
pluginKey,
})

const generics = new FunctionParams()
const params = new FunctionParams()
const queryParams = new FunctionParams()
const client = {
Expand All @@ -314,12 +313,6 @@
withHeaders: !!schemas.headerParams?.name,
}

generics.add([
{ type: 'TData', default: `${factory.name}["response"]` },
suspense ? undefined : { type: 'TQueryData', default: `${factory.name}["response"]` },
{ type: `TQueryKey extends QueryKey`, default: queryKeyType },
])

const pathParams = getParams(schemas.pathParams, {}).toString()
const resultGenerics = [
`TData`,
Expand Down Expand Up @@ -402,7 +395,6 @@

<Template
name={[name, infinite ? 'Infinite' : undefined, suspense ? 'Suspense' : undefined].filter(Boolean).join('')}
generics={generics.toString()}
JSDoc={{ comments: getComments(operation) }}
params={params.toString()}
returnType={`${resultType}<${resultGenerics.join(', ')}>`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function CreatePetsQueryOptions<TData = CreatePets['response'], TQueryDat
* @summary Create a pet
* @link /pets */

export function useCreatePets<TData = CreatePets['response'], TQueryData = CreatePets['response'], TQueryKey extends QueryKey = CreatePetsQueryKey>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need data and queryKey, without you can not set select with correct types

export function useCreatePets(
options: {
query?: UseBaseQueryOptions<CreatePets['data'], CreatePets['error'], TData, TQueryData, TQueryKey>
client?: CreatePets['client']['parameters']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function ShowPetByIdQueryOptions<TData = ShowPetById['response'], TQueryD
* @summary Info for a specific pet
* @link /pets/:petId */

export function useShowPetById<TData = ShowPetById['response'], TQueryData = ShowPetById['response'], TQueryKey extends QueryKey = ShowPetByIdQueryKey>(
export function useShowPetById(
petId: ShowPetByIdPathParams['petId'],
testId: ShowPetByIdPathParams['testId'],
options: {
Expand Down
Loading