Skip to content

Commit 81de301

Browse files
committed
Explicitly name destructured options types
Works around microsoft/TypeScript#64431
1 parent 71db2d4 commit 81de301

3 files changed

Lines changed: 26 additions & 15 deletions

File tree

‎packages/toolkit/src/createSlice.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,10 @@ export function buildCreateSlice({ creators }: BuildCreateSliceConfig = {}) {
809809
caseReducers: context.sliceCaseReducersByName as any,
810810
getInitialState,
811811
...makeSelectorProps(reducerPath),
812-
injectInto(injectable, { reducerPath: pathOpt, ...config } = {}) {
812+
injectInto(
813+
injectable,
814+
{ reducerPath: pathOpt, ...config }: InjectIntoConfig<string> = {},
815+
) {
813816
const newReducerPath = pathOpt ?? reducerPath
814817
injectable.inject({ reducerPath: newReducerPath, reducer }, config)
815818
return {

‎packages/toolkit/src/query/core/buildInitiate.ts‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,20 +153,22 @@ export type InfiniteQueryActionCreatorResult<
153153
): InfiniteQueryActionCreatorResult<D>
154154
}
155155

156+
type StartMutationActionCreatorOptions = {
157+
/**
158+
* If this mutation should be tracked in the store.
159+
* If you just want to manually trigger this mutation using `dispatch` and don't care about the
160+
* result, state & potential errors being held in store, you can set this to false.
161+
* (defaults to `true`)
162+
*/
163+
track?: boolean
164+
fixedCacheKey?: string
165+
}
166+
156167
type StartMutationActionCreator<
157168
D extends MutationDefinition<any, any, any, any>,
158169
> = (
159170
arg: QueryArgFrom<D>,
160-
options?: {
161-
/**
162-
* If this mutation should be tracked in the store.
163-
* If you just want to manually trigger this mutation using `dispatch` and don't care about the
164-
* result, state & potential errors being held in store, you can set this to false.
165-
* (defaults to `true`)
166-
*/
167-
track?: boolean
168-
fixedCacheKey?: string
169-
},
171+
options?: StartMutationActionCreatorOptions,
170172
) => ThunkAction<MutationActionCreatorResult<D>, any, any, UnknownAction>
171173

172174
export type MutationActionCreatorResult<
@@ -389,7 +391,7 @@ You must add the middleware for RTK-Query to function correctly!`,
389391
subscriptionOptions,
390392
[forceQueryFnSymbol]: forceQueryFn,
391393
...rest
392-
} = {},
394+
}: StartQueryActionCreatorOptions = {},
393395
) =>
394396
(dispatch, getState) => {
395397
const queryCacheKey = serializeQueryArgs({
@@ -545,7 +547,10 @@ You must add the middleware for RTK-Query to function correctly!`,
545547
function buildInitiateMutation(
546548
endpointName: string,
547549
): StartMutationActionCreator<any> {
548-
return (arg, { track = true, fixedCacheKey } = {}) =>
550+
return (
551+
arg,
552+
{ track = true, fixedCacheKey }: StartMutationActionCreatorOptions = {},
553+
) =>
549554
(dispatch, getState) => {
550555
const thunk = mutationThunk({
551556
type: 'mutation',

‎packages/toolkit/src/query/react/buildHooks.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,7 +1953,7 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
19531953
refetchOnFocus,
19541954
pollingInterval = 0,
19551955
skipPollingIfUnfocused = false,
1956-
} = {}) => {
1956+
}: SubscriptionOptions = {}) => {
19571957
const { initiate } = api.endpoints[endpointName] as ApiEndpointQuery<
19581958
QueryDefinition<any, any, any, any, any>,
19591959
Definitions
@@ -2213,7 +2213,10 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
22132213
}
22142214

22152215
function buildMutationHook(name: string): UseMutation<any> {
2216-
return ({ selectFromResult, fixedCacheKey } = {}) => {
2216+
return ({
2217+
selectFromResult,
2218+
fixedCacheKey,
2219+
}: UseMutationStateOptions<any, any> = {}) => {
22172220
const { select, initiate } = api.endpoints[name] as ApiEndpointMutation<
22182221
MutationDefinition<any, any, any, any, any>,
22192222
Definitions

0 commit comments

Comments
 (0)