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
exportfunctionquery(){constgetData=<Textendsstring>(select: T='id,name'asT)=>{returndb.from('table').select(select)}return{ getData }}constdata=awaitquery().getData('id,name')// this is already infered since the underlying library already returns correct types depending on select value (in my case supabase)
But when it's needed to extract that return type and use it in somewhere else. For example in a React Component that is passed as prop. I need to extract the type of getData with the generic select value that is provided.
Possible workarounds at the moment
Set generic into wrapper
exportfunctionquery<Textendsstring>(){constgetData=(select: T='id,name'asT)=>{returndb.from('table').select(select)}return{ getData }}// this results with other type errors.
Or write another function and get it's type. Which is just duplication.
It looks like a duplicate but not exactly. Wrapped functions are bit more different. If it wasn't wrapped, i could just pass generic to that function easily with. ReturnType<typeof getData<'id,name'>>
Suggestion
Allowing extracting
ReturnType
of wrapped function with generics.🔍 Search Terms
✅ Viability Checklist
My suggestion meets these guidelines:
💻 Use Cases
But when it's needed to extract that return type and use it in somewhere else. For example in a React Component that is passed as prop. I need to extract the type of
getData
with the generic select value that is provided.Possible workarounds at the moment
Set generic into wrapper
Or write another function and get it's type. Which is just duplication.
The text was updated successfully, but these errors were encountered: