David Alonso
David Alonso5mo ago

How to define a type that is the return type of a Convex query

Suppose I want to declare a type at the top of a file like so:
type FirestoreCollectionResult = {
db: Firestore;
cFirestoreConfig: any;
};
type FirestoreCollectionResult = {
db: Firestore;
cFirestoreConfig: any;
};
How could i set cFirestoreConfig to the output of a convex query or part of it?
6 Replies
Hmza
Hmza5mo ago
you can use Doc<"tablename"> the data returned from convex query wraps this type. Doc can be imported from _generated folder in convex.
ballingt
ballingt5mo ago
Set as in cast the return value of a Convex query to this type? In your whery you can write
const result: FirestoreCollectionResult = blah blah blah
return result;
const result: FirestoreCollectionResult = blah blah blah
return result;
is that what you're talking about?
David Alonso
David AlonsoOP5mo ago
I want to replace any in the code snippet above by the type returned by a specific query. Sometimes these can be pretty complicated types and declaring them manually is a lot of work
jamwt
jamwt5mo ago
Module: server | Convex Developer Hub
Utilities for implementing server-side Convex query and mutation functions.
David Alonso
David AlonsoOP5mo ago
beautiful! FunctionArgs is also super useful for defining optimistic update functions somewhere else

Did you find this page helpful?