(Solved) Infer result of select
(where
WhatDoIPutHere becomes number)8 Replies
stormy-gold•4mo ago
Lucky for you, Dominik just wrote an in depth blog on this
https://tkdodo.eu/blog/react-query-selectors-supercharged
React Query Selectors, Supercharged
How to get the most out of select, sprinkled with some TypeScript tips.
unwilling-turquoiseOP•4mo ago
i read the whole article but i don't think it covers inferring the return type of an inline function passed to
select.
only how to abstract the function itself as a parameter.plain-purple•4mo ago
WhatDoIPutHere is whatever the queryFn returns, as that is the input for select. It gets inferred if you inline it
unwilling-turquoiseOP•4mo ago
i should have named the function "handleSelectedQueryData".
what if i have many inline select functions and still need to get their return type?
plain-purple•4mo ago
Please show a typescript playground
unwilling-turquoiseOP•4mo ago
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
plain-purple•4mo ago
not really possible unless you define it inilne and have access to
myQuery
https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgVwM4FMCKz1QJ5wC+cAZlBCHAEQACMAhgHaoMDGA1gPRTr2swBaAI458VANwAoSawjN4IPNlwEAvCgzL8ACgSS4cESoDS6PAC44AbSrszVALoAafXAwAbdP0vaAlHFUAPjgARklCX2lZeTgACyYAE08AEXoGALhtBLT6SwA5OTzkd3d6ACNPAB4YPDB0CBI4RS08KwBybIY2h0D-IMRXAyHh4c5OYYA9AH5XMbiIAHc4GAhl2vRl2I3UYABzRjTkHkzgRhJcakZkEDLcKl8ZwmlgRu1m0TwAOmBUAGVkVisdCoVD+PQGaIsRBwTr0IgZd4qVzxRhJdCpBhZHKRQhAATS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
unwilling-turquoiseOP•3mo ago
In case someone comes across this (probably me in a few months lmao):