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
erquhart
erquhart2y ago
Are you using the return type in a convex function or in the client (react)?
ballingt
ballingt2y ago
You can type import the query and get the ReturnType<typeof yourQuery>, or more convenient maybe api.foo.bar["_returnType"]
ian
ian2y ago
Where yourQuery can be api.foo.bar, right Tom? Or just referencing the function directly if it’s server-side?
ballingt
ballingt2y ago
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.
Chad Maycumber
Chad MaycumberOP2y ago
Cool thanks these both look perfect

Did you find this page helpful?