-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix: fix the type of the argument of KeyedMutator
for populateCache
#2933
base: main
Are you sure you want to change the base?
Changes from all commits
d2a4282
cc1ac3e
4882ab3
b4681da
89611e3
8ea098d
52cf67d
27f0dbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ import { | |
import type { | ||
BareFetcher, | ||
SWRHook, | ||
MutatorCallback, | ||
Middleware, | ||
GlobalState | ||
} from '../_internal' | ||
|
@@ -238,16 +237,9 @@ export const infinite = (<Data, Error>(useSWRNext: SWRHook) => | |
config | ||
) | ||
|
||
const mutate = useCallback( | ||
const mutate = useCallback<SWRInfiniteKeyedMutator<Data[]>>( | ||
// eslint-disable-next-line func-names | ||
function <T = Data[]>( | ||
data?: | ||
| undefined | ||
| Data[] | ||
| Promise<Data[] | undefined> | ||
| MutatorCallback<Data[]>, | ||
opts?: undefined | boolean | SWRInfiniteMutatorOptions<Data[], T> | ||
) { | ||
function (data?: any, opts?: any) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I request you for comments for attaching The reason for attachching any is below. I thought the type of the arguments The type of But I I do so and pass the data to
If I could know the type of Do you know how to solve this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My idea for how to solve this problem.
// this is invalid code, just for sharing my idea
if (typeof Data === typeof MutationData){
} else {
...
}
const mutate = useCallback<SWRInfiniteKeyedMutator<Data[]>>(
// eslint-disable-next-line func-names
function <MutationData = Data[]>(
data?:
| Data
| Promise<Data | undefined>
| MutatorCallback<Data>
| MutationData
| Promise<MutationData | undefined>
| MutatorCallback<MutationData>
| undefined,
opts?: boolean | SWRInfiniteMutatorOptions<Data[], MutationData>
): Promise<Data[] | MutationData | undefined> {
// contents
return arguments.length
? swr.mutate<Data[]>(
data as any,
{
...options,
revalidate: shouldRevalidate
} as any
)
: swr.mutate()
},
// swr.mutate is always the same reference
// eslint-disable-next-line react-hooks/exhaustive-deps
[infiniteKey, cache]
) |
||
// When passing as a boolean, it's explicitly used to disable/enable | ||
// revalidation. | ||
const options = | ||
|
There was a problem hiding this comment.
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.