TanStackT
TanStackโ€ข8mo agoโ€ข
3 replies
rubber-blue

Query Return Type when using `select`

Hi all.

I guess this is more of a TS question than query related but I've been wondering how to best practice the return type when using select on data retrieval?

My query calls the API to get a data set which has it's own type - but I've also built in a parsing flag for the data set which returns another type if true.

The type gets inferred as Type1 | Type2 . Is there a good way to infer type 2 only if the flag is true and use type1 if the flag is false?

Or is it best to just split the query function into two separate entities ( with same queryKey , but one uses the parsing and the other doesn't )?

Cheers on any info or pointers what's cleaner ๐Ÿ˜„
Was this page helpful?