Skip to content
15 changes: 9 additions & 6 deletions src/_internal/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,21 +428,24 @@ export interface ScopedMutator {
* @typeParam Data - The type of the data related to the key
* @typeParam MutationData - The type of the data returned by the mutator
*/
<Data = any, T = Data>(
<Data = any, MutationData = Data>(
key: Arguments,
data?: T | Promise<T> | MutatorCallback<T>,
opts?: boolean | MutatorOptions<Data, T>
): Promise<T | undefined>
data?: MutationData | Promise<MutationData> | MutatorCallback<MutationData>,
opts?: boolean | MutatorOptions<Data, MutationData>
): Promise<MutationData | undefined>
Comment on lines +431 to +435
Copy link
Author

@Key5n Key5n Apr 8, 2024

Choose a reason for hiding this comment

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

This is just refactoring for name consistency.
Since there is @typeParam MutationData comment docs, I think the generics parameter T should follow that.

}

/**
* @typeParam Data - The type of the data related to the key
* @typeParam MutationData - The type of the data returned by the mutator
*/
export type KeyedMutator<Data> = <MutationData = Data>(
data?: Data | Promise<Data | undefined> | MutatorCallback<Data>,
data?:
| MutationData
| Promise<MutationData | undefined>
| MutatorCallback<MutationData>,
opts?: boolean | MutatorOptions<Data, MutationData>
) => Promise<Data | MutationData | undefined>
) => Promise<MutationData | undefined>

export type SWRConfiguration<
Data = any,
Expand Down
11 changes: 5 additions & 6 deletions src/infinite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,12 @@ export const infinite = (<Data, Error>(useSWRNext: SWRHook) =>

const mutate = useCallback(
// eslint-disable-next-line func-names
function <T = Data[]>(
function <MutationData = Data[]>(
data?:
| undefined
| Data[]
| Promise<Data[] | undefined>
| MutatorCallback<Data[]>,
opts?: undefined | boolean | SWRInfiniteMutatorOptions<Data[], T>
| MutationData
| Promise<MutationData | undefined>
| MutatorCallback<MutationData>,
opts?: boolean | SWRInfiniteMutatorOptions<Data[], MutationData>
) {
// When passing as a boolean, it's explicitly used to disable/enable
// revalidation.
Expand Down