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

Clean up types #1016

Merged
merged 8 commits into from
Mar 8, 2021
Merged

Clean up types #1016

merged 8 commits into from
Mar 8, 2021

Conversation

shuding
Copy link
Member

@shuding shuding commented Mar 6, 2021

This PR does 2 things:

  1. The exported type ConfigInterface was changed in types: makes types fn and config and key more strictly #946, which might be breaking. However it's not released as stable yet. This PR fixes it.
  2. Renames some types to be more consistent. Also marks the old ones as deprecated.

For 1, the cause is that properties in ConfigInterface are no longer optional. And if a user creates a custom hook the type might be broken:

import useSWR, { ConfigInterface } from 'swr'

function useData (opts: ConfigInterface) {
  return useSWR('/api', opts)
}

useData({}) // ← error because all fields are required

For 2, updated types are:

Current New
keyInterface Key
ConfigInterface SWRConfiguration
responseInterface SWRResponse
SWRInfiniteConfigInterface SWRInfiniteConfiguration
SWRInfiniteResponseInterface SWRInfiniteResponse
revalidateType Revalidator
RevalidateOptionInterface RevalidatorOptions
CacheInterface Cache

The deprecated ones will be kept until 1.0.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 6, 2021

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 4d9a0bf:

Sandbox Source
SWR-Basic Configuration
SWR-States Configuration
SWR-Infinite Configuration

@shuding shuding marked this pull request as ready for review March 6, 2021 20:24
@shuding shuding requested a review from huozhi March 6, 2021 20:25
src/types.ts Show resolved Hide resolved
src/types.ts Show resolved Hide resolved
Copy link
Member

@huozhi huozhi left a comment

Choose a reason for hiding this comment

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

I just encounter an issue like specifying the ConfigInterface in another PR. Could we consider exporting the paritial one?

export type ConfigInterface = Partial<{....}>

@shuding
Copy link
Member Author

shuding commented Mar 7, 2021

It is already the partial one: Partial<Configuration<Data, Error, Fn>>

@shuding
Copy link
Member Author

shuding commented Mar 7, 2021

Published as swr@0.4.3-beta.3.

This was referenced Mar 15, 2021
@ivan-kleshnin
Copy link

Maybe also rename SWRConfig to SWRProvider?

SWRConfig (component) vs SWRConfiguration (type) – way too similar names.

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 this pull request may close these issues.

3 participants