Add optional name parameter to v.object() for cross-language type safety
#248
+18
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds an optional
nameparameter to thev.object()validator constructor to enable better type generation for Convex clients in languages other than TypeScript.Problem
When generating type-safe clients for languages without TypeScript's powerful type system (like Python, Java, Go, etc.), we need consistent, reusable type names for object schemas. Currently, without named objects, client generators must create arbitrary names like
Object123orAnonymousObject, making types non-reusable and harder to work with. These types are also not the same across different requests. So 2 functions which return the identical object, return different classes.Solution
Add an optional
nameparameter tov.object()that allows developers to specify meaningful names for their object types:This would allow client library authors to generate data models like:
which could be used across multiple different requests.
The alternative would be:
While TypeScript already handles types internally, providing explicit names could also benefit code generation and type declarations for TypeScript itself. The primary motivation, however, is to support non-TypeScript languages.
Backward Compatibility
This change is fully backward compatible:
v.object(fields)continues to work unchangednameparameter is optional and defaults toundefined