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

Better TS types #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Better TS types #2

wants to merge 2 commits into from

Conversation

jdeniau
Copy link

@jdeniau jdeniau commented Sep 30, 2024

Hi,

This PR tries to improve TS typings.

The main changes:

unknown over any

unkown is prefer over any , as any disable type checking. See https://typescript-eslint.io/rules/no-explicit-any/

Promise input and return type

The return type of the promise is the same as the input type, this way, TS can infer the proper return type of this code:

const fetch = (): Promise<SomeType>;

const swrFetch = swrPromise(fetch); // properly infer as `(): Promise<SomeType>

Export type declaration

I exported the main types that could be used in several circumstances, like wrapping swr into another function, or overriding default store (in that case, the Store interface is helpful)

Typing the store

I typed the Store class as the key is an array, and the data is a CacheNode

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.

1 participant