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

Conditional rendering does not have correct type #2970

Open
benpierce-tumelo opened this issue May 22, 2024 · 0 comments
Open

Conditional rendering does not have correct type #2970

benpierce-tumelo opened this issue May 22, 2024 · 0 comments

Comments

@benpierce-tumelo
Copy link

benpierce-tumelo commented May 22, 2024

Bug report

Description / Observed Behavior

Conditional fetching does not return expected type.

Expected Behavior

The response type should be a union type of the fetcher response type and undefined.

Repro Steps / Code Example

For this example code:

 const fetcher: async (): Promise<ResponseType> => {...}
const response = useSWR(shouldFetch ? '/api/data' : null, fetcher)

The type of response is SWRResponse when it should be SWRResponse<ResponseType | undefined> as when shouldFetch is true the data property in the SWRResponse is undefined.

Additional Context

SWR version.
2.2.5

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

No branches or pull requests

1 participant