-
Notifications
You must be signed in to change notification settings - Fork 1.3k
types: makes types fn and config and key more strictly #946
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
Conversation
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. Latest deployment of this branch, based on commit 8d15462:
|
// `null` is used for a hack to manage shared state with SWR | ||
// https://github.com/vercel/swr/pull/918 | ||
export type fetcherFn<Data> = ((...args: any) => Data | Promise<Data>) | null | ||
export type fetcherFn<Data> = (...args: any) => Data | Promise<Data> |
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.
null
is only accepted for useSWR
and useSWRInfinite
doesn't accept null
as the fetcher, so I've moved null
to the argument of useSWR
.
export interface ConfigInterface< | ||
Data = any, | ||
Error = any, | ||
Fn extends fetcherFn<Data> = fetcherFn<Data> | ||
> { | ||
errorRetryInterval?: number | ||
errorRetryInterval: number |
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.
These values are having default values as defaultConfig
, so we don't have to make the types optional.
): SWRInfiniteResponseInterface<Data, Error> | ||
function useSWRInfinite<Data = any, Error = any>( | ||
...args | ||
getKey: KeyLoader<Data>, |
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.
getKey
is not an optional argument.
config?: ConfigInterface<Data, Error> | ||
// `null` is used for a hack to manage shared state with SWR | ||
// https://github.com/vercel/swr/pull/918 | ||
fn?: fetcherFn<Data> | null, |
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.
null
should be accepted
FYI. I had enabled the strict mode of typescript in the next branch. 😁 |
@promer94 |
@koba04 We are aiming to v1 and we put all the things that might break the compatibility into that branch. But if you think that strict mode is safe to be added earlier, we can cherry-pick it and get it on master :) |
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.
Thanks!
@shuding Thank you! |
This is a PR to make internal types (
fn
,config
, andkey
) more strictly.This helps refactoring and code completion.
In the future, it would be nice if SWR could enable the TypeScript's
strict
mode.