You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the function passed as optimisticData in mutate gets two parameters, where currentData can explicitly be undefined regardless of Data (most recent updates from this PR: https://github.com/vercel/swr/pull/2708/files#diff-947adbc8aa4f84c3191ad83c84d1344a1fd311224f73a9f92e7b9eaa73860508R324). if you are using the function version of optimisticData though, it's very possible you can't create the whole object expected, so can we explicitly allow the return value of optimisticData to be undefined?
Right now this gets a type error because optimisticData infers that the return value should be DataType.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
the function passed as
optimisticDatain mutate gets two parameters, wherecurrentDatacan explicitly be undefined regardless ofData(most recent updates from this PR: https://github.com/vercel/swr/pull/2708/files#diff-947adbc8aa4f84c3191ad83c84d1344a1fd311224f73a9f92e7b9eaa73860508R324). if you are using the function version ofoptimisticDatathough, it's very possible you can't create the whole object expected, so can we explicitly allow the return value ofoptimisticDatato be undefined?Right now this gets a type error because
optimisticDatainfers that the return value should beDataType.It can be worked around by changing the first line to explicitly have the data type or undefined
The addition of an explicit type or undefined lets this work. but the value of swr.data is already allowed to be undefined.
Can we have optimisticData's inferred type also explicitly allow returning
undefined?All reactions