#Types and Validators in TypeScript: A Convex Cookbook
9 messages · Page 1 of 1 (latest)
I'm curious, is there any difference in using Infer on the validator, or using the .type directly from the validator?
Infer
export type Challenge = Infer<typeof challengeValidator>
.type
export type Challenge = typeof challengeValidator.type
It looks to me like those should be the same @shut galleon, per the definition of Infer (https://github.com/get-convex/convex-js/blob/32ff1dc1190e35223bda44c41f51a237960da3e0/src/values/validator.ts#L289):
export type Infer<V extends Validator<any, any, any>> = V["type"];
Ahh yeah I see. So just a preference thing I suppose.
I think using Infer is likely better, just for the reason that that's the intended public API for extracting the type from the Validator, and the implementation details of how that type is stored on the Validator could technically change!
Yeah I think ['type'] is technically internal
Good point. Also prefer the Infer syntax.
Nice article. I wonder if there is scope for doing an article that talks about evolving your schema over time, techniques and methods for it.
For me that’s one of the biggest strengths of convex DB flexible schema that you can use union and literal to extend a table in the future should you want to store different “kinds” of things in it later on