-
I'm trying to implement a custom hook that performs a transform on a query result, and have the custom hook return the exact same
However, even though the overridden data is the same shape as Here is a sandbox with the compiler error: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
I think that's because That is insanely unnecessary 😅 , but it would look something like this (ported to v4): https://codesandbox.io/s/thirsty-wescoff-vhxbw7?file=/src/App.tsx:523-802 The easiest thing to do is to just remove the return type annotation from your custom hook and let typescript infer the complex union type. also, depending on what you'd like to transform, the |
Beta Was this translation helpful? Give feedback.
I think that's because
data
is part of the large discriminated union type. If you add data unconditionally, the type needs to be aQueryObserverSuccessResult
. So you'd also have to set status and derived booleans accordingly.That is insanely unnecessary 😅 , but it would look something like this (ported to v4): https://codesandbox.io/s/thirsty-wescoff-vhxbw7?file=/src/App.tsx:523-802
The easiest thing to do is to just remove the return type annotation from your custom hook and let typescript infer the complex union type.
also, depending on what you'd like to transform, the
select
option might be better suited.