swr
swr copied to clipboard
fix: fix the type of the argument of `KeyedMutator` for `populateCache`
closes https://github.com/vercel/swr/issues/2975
What this PR does
This PR fixes a type error problem related to populateCache and bound mutate.
Now, the first argument of bound mutate only accepts the type of the returned value of fetcher by useSWR.
But in order to make use of populateCache, the first argument of mutate should accept any type of API fetching result.
So I changed the type of the first argument from Data (which is the type of data useSWR fetches) into MutationData (which is the type of the data returned by the mutator)
In addition, I changed types in infinite since it had error when I changed the type of KeyedMutator .
This pull request is automatically built and testable in CodeSandbox.
To see build info of the built libraries, click here or the icon next to each commit SHA.
Sure! Thank you for comment.
If you want to modify my PR, please do at your mercy.
Sorry, I didn't notice that some tests were unpassed. I will fix it.
@huozhi
A PR I submitted fails some tests, so I've changed almost of whole things and add tests. Sorry for begging you reviews again.
I changed the type KeyedMutator using overload function, making populateCache is necessary when MutationData (the type of the first argument of bound mutate) is different from the type of Data.
This achieves strict type attaching.