Skip to content
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

SWRHook noting enforcing fetch arguments and Key types #2758

Closed
wcatron opened this issue Aug 24, 2023 · 0 comments · Fixed by #2759
Closed

SWRHook noting enforcing fetch arguments and Key types #2758

wcatron opened this issue Aug 24, 2023 · 0 comments · Fixed by #2759

Comments

@wcatron
Copy link
Contributor

wcatron commented Aug 24, 2023

Bug report

Description / Observed Behavior

While trying to enforce types of the arguments of our fetcher the type override for SWRHooks fell through to BareFetcher which allowed any arguments even if they did not match the key.

Expected Behavior

Should throw a typescript error because the types don't match.

Repro Steps / Code Example

const fetcher = ({ url }:{ url: string }) => url
// No typescript error
useSWR({ path: '/api' }, fetcher)

Should throw a typescript error because { path: string } does not match { url: string }.

Additional Context

  • SWR version 2.2.1
  • Attempted to remove arguments from BaseFetcher which seemed reasonable that you shouldn't allow the BaseFetcher to contain arguments otherwise it's not a BaseFetcher, this caused tons of cascading issues.
  • I believe I have a solution replacing the BaseFetcher override with a more basic type. It currently doesn't seem to cause cascading type issues and provides the expected behavior.
  • This occurred while using the Fetcher type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant