Using mutate with optimisticData: typescript is giving me a hard time #2358
Unanswered
svenlombaert
asked this question in
Q&A
Replies: 1 comment
-
I have a similar issue with the same error. I have posted a SO. Hopefully will be resolved soon as it makes it difficult to use (need to @ts-ignore everywhere). Thanks! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there,
Was just upgrading from 1.x to 2.x. I love the Optimistic UI approach, it's removing a lot of our boilerplate. I have one issue though, related to typescript.
I'm using swr like this:
Basically telling that we receive an
AxiosResponse
with a genericData
type inside it's data key. That's all good. Because of this,mutate
is automatically inferred to this type:And I mutate like this:
Code works perfectly, gets rolled back on error, all good. It's just that typescript is complaining that
updateNotificationStatus
is returning aPromise<void>
whilst it expectsPromise<AxiosResponse<NotificationSettingApiResponse, any>>
Anyone has found a way to tell typescript this is fine? Because if you set
populateCache: false
, it doesn't matter whatupdateNotificationStatus
returns, it's not used anyway.Hope this was clear 😅
Beta Was this translation helpful? Give feedback.
All reactions