Use enabled prop for type narrowing
Simple question: Would it be feasible to use the 'enabled' prop to narrow down the type of variables used in the fetch function?
Codesandbox to show the issue:
https://codesandbox.io/p/sandbox/billowing-thunder-qwdy98?file=%2Fsrc%2FApp.tsx%3A2%2C37
4 Replies
extended-salmon•2y ago
The problem with this is that in both cases
id
refers to the id
in the props which can be undefined. There's no connection between the enabled
check and the id
you pass to the queryFn
. TS simply can not narrow this property.
extended-salmon•2y ago
React Query and TypeScript
Combine two of the most powerful tools for React Apps to produce great user experience, developer experience and type safety.
constant-blue•2y ago
continuing-cyanOP•2y ago
Thnks!