RJR
Convex Community3y ago
2 replies
RJ

Infer type from ObjectValidator which forbids extra properties

I ran into an issue today where I was passing in an object to a validated Convex function which had extra fields not specified by the validator for that function. I got a nice runtime error message in the Convex dashboard logs (huzzah!) but TypeScript had no issue with letting me make this mistake.

I don't know how easy it would be to do, but it would be nice to have the inferred TS types of a validator forbid extra properties (like what this utility function does: https://github.com/sindresorhus/type-fest/blob/main/source/exact.d.ts), so that this could be a compilation error rather than a runtime error.
Was this page helpful?