Skip to content

Commit

Permalink
split types
Browse files Browse the repository at this point in the history
  • Loading branch information
ben.durrant committed Oct 2, 2023
1 parent eb55056 commit 928279b
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions packages/toolkit/src/query/react/namedHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,37 @@ import type {
QueryDefinition,
} from '@reduxjs/toolkit/query'

export type HooksWithUniqueNames<Definitions extends EndpointDefinitions> = {
type QueryHookNames<Definitions extends EndpointDefinitions> = {
[K in keyof Definitions as Definitions[K] extends {
type: DefinitionType.query
}
? `use${Capitalize<K & string>}Query`
: never]: UseQuery<
Extract<Definitions[K], QueryDefinition<any, any, any, any>>
>
} &
{
[K in keyof Definitions as Definitions[K] extends {
type: DefinitionType.query
}
? `useLazy${Capitalize<K & string>}Query`
: never]: UseLazyQuery<
Extract<Definitions[K], QueryDefinition<any, any, any, any>>
>
} &
{
[K in keyof Definitions as Definitions[K] extends {
type: DefinitionType.mutation
}
? `use${Capitalize<K & string>}Mutation`
: never]: UseMutation<
Extract<Definitions[K], MutationDefinition<any, any, any, any>>
>
}

type LazyQueryHookNames<Definitions extends EndpointDefinitions> = {
[K in keyof Definitions as Definitions[K] extends {
type: DefinitionType.query
}
? `useLazy${Capitalize<K & string>}Query`
: never]: UseLazyQuery<
Extract<Definitions[K], QueryDefinition<any, any, any, any>>
>
}

type MutationHookNames<Definitions extends EndpointDefinitions> = {
[K in keyof Definitions as Definitions[K] extends {
type: DefinitionType.mutation
}
? `use${Capitalize<K & string>}Mutation`
: never]: UseMutation<
Extract<Definitions[K], MutationDefinition<any, any, any, any>>
>
}

export type HooksWithUniqueNames<Definitions extends EndpointDefinitions> =
QueryHookNames<Definitions> &
LazyQueryHookNames<Definitions> &
MutationHookNames<Definitions>

0 comments on commit 928279b

Please sign in to comment.