David Alonso
David Alonso8mo ago

Weird type inference behavior

I've tried to restart my TS server but I keep getting weird inference on this line: And no idea why...
No description
No description
5 Replies
Michal Srb
Michal Srb8mo ago
Notice the | 30 more. Type inference of the schema is failing for you, and you’re getting a union of all your document types. I’d revert changes you made and reaply to see what’s causing it.
David Alonso
David AlonsoOP8mo ago
hmm that's really weird tho, the rest of my codebase doesn't show any errors or this weird behavior. for now i just added ts-ignore on the lines that access fields of field 🫣
Michal Srb
Michal Srb8mo ago
What about a typo somewhere. Is it firestoreFields in both the field type and the table name?
ampp
ampp8mo ago
Ive seen this quite a bit and have wondered where i should see it and not see it. I use ents however. But i do have a native convex file right now. Its simple to trigger this and to fix it.
export const getAnyDoc = internalQuery({
args: { id: v.any() },
handler: async (ctx, args) => {
const doc = await ctx.db.get(args.id as any);
return doc;
},
});

export const getAnyUsersDoc = internalQuery({
args: { id: v.any() },
handler: async (ctx, args) => {
const doc = await ctx.db.get(args.id as Id<"users">);
return doc;
},
});
export const getAnyDoc = internalQuery({
args: { id: v.any() },
handler: async (ctx, args) => {
const doc = await ctx.db.get(args.id as any);
return doc;
},
});

export const getAnyUsersDoc = internalQuery({
args: { id: v.any() },
handler: async (ctx, args) => {
const doc = await ctx.db.get(args.id as Id<"users">);
return doc;
},
});
David Alonso
David AlonsoOP8mo ago
Thanks @ampp that's a nice workaround!

Did you find this page helpful?