Replies: 1 comment
-
Isn't this just a TypeScript LSP concern rather than an SWR one? You haven't actually confirmed that
Therefore a simple example like this guarantees that
However, you have not provided SWR with any initial data or a suspense guarantee, so from SWR's perspective there is every chance you will not receive any data from your fetcher and thus have no data to serve. Otherwise, a simple check that |
Beta Was this translation helpful? Give feedback.
-
The sample code at here:
In my opinion, I think if
isLoading
is false that means fetcher is executed finished, and iferror
is null, that means the executed result is successful, so data is must not undefined.But I see the TypeScript report the data may be undefined in this case, is there any way to optimize the logic of typing narrow? Actually, I think in this condition, SWR should assert the data must not be undefined, is this an issue that can be improved?
Thank you very much!
Beta Was this translation helpful? Give feedback.
All reactions