tom
tom7d ago

The Shadow Types

for convex side code (e.g. an action calling a query) i import api or internal from an alternative set of types
import { api, internal } from "../../_convex/shadow";
import { api, internal } from "../../_convex/shadow";
these being generated by the convex helpers which is fully materialized, just the way components already are in the standard _generated/api.d.ts this allows FunctionReturnType to just work on the action reference, and we get full typing (no ts circular error), without creating extra hard coded types catch is, anytime time the query the action uses changes, we need to re run the convex helper but this seems better than manually updating duplicate explicit types?
1 Reply
deen
deen7d ago
i've never thought of doing it like this. i mean, this IS a solution. none of them are satisfying because the problem itself is pretty dumb i actually haven't used the typegen in a while, but did they ever add v.record? i remember having some issues i use types inferred from validators heavily around a mature convex app, which because they're not actually coming from the data model, i can use in a const result: TheType = ctx.runSomething if necessary but i've only recently noticed that this issue usually appears when you return something from an action. which actually is often not necessary? if you're persisting something to the db you can return data from the action to like show it nicely in the dashboard, but that's not very important and can create this mess but if you are doing that, annotating your action function with return type of any also generally stops it and doesn't actually matter

Did you find this page helpful?