Good way to get a return type?
What's the best way in typescript to grab the return type from a query with Convex 17+?
5 Replies
Are you using the return type in a convex function or in the client (react)?
You can type import the query and get the ReturnType<typeof yourQuery>, or more convenient maybe api.foo.bar["_returnType"]
Where yourQuery can be api.foo.bar, right Tom? Or just referencing the function directly if it’s server-side?
Ah sorry unclear example, yeah api.directoryName.fileName.yourQuery["_returnType"]. Both of these work client- or server-side, but it's important to use a type import instead of a normal import if you use the first method.
Cool thanks these both look perfect