ampp
ampp•6mo ago

btw the dashboard custom query is always

btw the dashboard custom query is always highlighting the keyvalue on this as invalid return await ctx.db.query("table").withIndex('field', (q) => q.eq('field', { keyValue: 'stringValue'})).take(1);
11 Replies
ari
ari•6mo ago
Thanks for the report, what does your schema look like for field? Scrolling over the highlight should give you an error message, let me know if it's unexpected
ampp
amppOP•6mo ago
v.optional(v.record(v.string(), union(v.ids))), Type 'string' is not assignable to type Id<""> | Id<> etc
lee
lee•6mo ago
what is union(v.ids)?
ampp
amppOP•6mo ago
v.union( v.id('table1'), v.id('table2'), etc
lee
lee•6mo ago
Is "stringValue" (from the original query) a valid id?
ampp
amppOP•6mo ago
Yeah i tried it with and without a valid id
lee
lee•6mo ago
cool afaik this should work. I'll let @ari take it from here
ampp
amppOP•6mo ago
the query does give a result, its just showing a syntax error that is not real
ari
ari•6mo ago
Was able to reproduce! I also reproduced it inside of a real query in my own project, so it's not just the dashboard, but a bug in our type system. We'll look into getting this fixed
ampp
amppOP•6mo ago
nice, yeah i had something similar in ts but not as a query, still trying to figure out what changes i'm going to make 🙃 . I was testing assumptions in the dashboard first. this is a expected use case right? .withIndex('field', (q) => q.gt('field', { keyValue: undefined})).take(10); to get records with keytype but any value, i just wish i could do that with .eq with that current error i cant exactly tell if this will pass ts. as the my ids union is non-optional
lee
lee•6mo ago
i would do .gte("field", { keyValue: null as any }) I don't think the undefined will work as a value in an object Also this doesn't mean "records with keytype but any value". It means "recods that sort after { keyValue: null } in the sort order where objects are ordered as tuples of (key, value) where keys are sorted. In this ordering {cat: 1, dog: 2} < {dog: null} < {dog: 1}

Did you find this page helpful?