🐐GoatGuy🐐
🐐GoatGuy🐐7mo ago

Weird type error when searching by Index

I get this error when trying to filter by an index, i created it in my schema too. Argument of type 'string' is not assignable to parameter of type 'never'.ts(2345) I ahve attached image of the query.
No description
No description
14 Replies
rishsane
rishsane7mo ago
never type?
🐐GoatGuy🐐
🐐GoatGuy🐐OP7mo ago
How can the parameter be never type though?
rishsane
rishsane7mo ago
Yup there is never type in typescript bro It's kind of special thing
🐐GoatGuy🐐
🐐GoatGuy🐐OP7mo ago
hmm i dont get it though, i created the index and ffollowed the docs, got no clue why it's giving me that linter error
sshader
sshader7mo ago
Try giving ctx a type annotation with MutaitonCtx from _generated/server? (https://labs.convex.dev/auth/advanced#writing-additional-data-during-authentication) TS needs the type annotation to know about all the tables defined in your schema (not just the ones defined in the auth schema)
Advanced: Details - Convex Auth
Authentication library for your Convex backend
rishsane
rishsane7mo ago
Do you know what is never type?
🐐GoatGuy🐐
🐐GoatGuy🐐OP7mo ago
I assume it means it never returns something?
ballingt
ballingt7mo ago
@🐐GoatGuy🐐 yeah see Sarah's comment, there's no way that this callback function can know about all your other tables, it only knows about those that come with Convex Auth unless you use MutationCtx explicitly When you write normal mutations etc. you use the mutation() wrapper imported from ../convex/_generated/server which imports from your schema. But the convexAuth() function doens't know about your schema, it's imported from the Convex Auth library.
rishsane
rishsane7mo ago
Right. But there are some special cases.
function fail(): never {
throw new Error("This function never returns!");
}

const result = fail(); // Type of `result` is `never`
function fail(): never {
throw new Error("This function never returns!");
}

const result = fail(); // Type of `result` is `never`
We can't console.log(result)
Hedi M. Sharif
Hedi M. Sharif3mo ago
Stil have the same issue, ant MutationCtx doesn't work, can someone help me with that
handler: async (ctx: MutationCtx, args) => {
const { userId, vehicleData } = args;

// Validate user exists
const user = await ctx.db.get(userId);
if (!user) {
throw new Error("User not found");
}

// Check if plate number already exists
const existingVehicle = await ctx.db
.query("vehicles")
.withIndex("by_plate", (q) =>
q.eq("plateNumber", vehicleData.plateNumber)
)
.first();
handler: async (ctx: MutationCtx, args) => {
const { userId, vehicleData } = args;

// Validate user exists
const user = await ctx.db.get(userId);
if (!user) {
throw new Error("User not found");
}

// Check if plate number already exists
const existingVehicle = await ctx.db
.query("vehicles")
.withIndex("by_plate", (q) =>
q.eq("plateNumber", vehicleData.plateNumber)
)
.first();
erquhart
erquhart3mo ago
Can you share a screenshot with type errors? MutationCtx missing the type either means it's not there, convex dev wasn't run, or there's some other error(s) throwing it off
Sara
Sara3mo ago
I thought of the same thing and ran something on my running dev, and it looks like that the db for that function is warepped in " ctx: GenericMutationCtx<AnyDataModel>" which is empty, I solved it by using adding a second query, and running the ct.runQuery, no errors there plus: just a small tip, the args already pass down exsistingUserId, I don't know if that would help in your case!
Sara
Sara3mo ago
No description
No description
erquhart
erquhart3mo ago
Interesting, wonder why that method isn't generic

Did you find this page helpful?