convex-helpers/packages/convex-helpers/s...
I'm trying to create my own version of the CRUD helper from convex-helpers, but was having some trouble getting handler function argument types to work out correctly. I looked and saw that convex-helpers uses a type assertion to get it to work: https://github.com/get-convex/convex-helpers/blob/main/packages/convex-helpers/server/crud.ts#L94-L95
I was curious about why the type assertion is needed here? Shouldn't TypeScript be able to infer the correct type of the arguments, or are we running into some kind of limitation?
GitHub
convex-helpers/packages/convex-helpers/server/crud.ts at main · get...
A collection of useful code to complement the official packages. - get-convex/convex-helpers
1 Reply
I've found TypeScript to be a bit finicky about these types. It's possible a newer version of TypeScript will be able to handle it, but I've found some trouble, especially when working with types like
WithoutSystemFields
that uses Expand
and BetterOmit
- they produce more readable types, but I think can trip up TypeScript for some reason. Just anecdotal, I haven't dug into why. In this case, it's taking an object that might have one or two system fields, conditionally removing them, and asserting it's the document without those fields, so I also hoped it'd just work.