EklayziaE
Convex Community13mo ago
15 replies
Eklayzia

No query type safety

Hello, I'm having trouble with why I'm not seeing proper type safety.

In my code:
  const objects = useQuery(api.schema.objects.getObjects);

objects is type any.

My schema:
import { authTables } from "@convex-dev/auth/server";
import { defineSchema } from "convex/server";
import { properties } from "./schema/properties";
import { objects } from "./schema/objects";
import { entities } from "./schema/entities";
import { entityValues } from "./schema/entityValues";

/**
 * Convex Auth requires indexes defined on `authTables`.
 * 
 * Objects are user defined.
 * Objects have user defined properties.
 * Entities are instances of objects with EntityValues for their properties.
 */
export default defineSchema({
    ...authTables,
    objects,
    properties,
    entities,
    entityValues,
});

schema/objects.ts
import { v } from "convex/values";
import { defineTable } from "convex/server";
import { query } from "@/_generated/server";
import { mutation } from "@/_generated/server";
import { Doc, Id } from "@/_generated/dataModel";

export const objects = defineTable({
    name: v.string(),
    description: v.string(),
    user: v.string(),
    icon: v.string(),
}).index("by_user", ["user"]);

export const getObjects = query({
    handler: async (ctx): Promise<Doc<"objects">[]> => {
        const identity = await ctx.auth.getUserIdentity();
        if (!identity) {
            throw new Error("Unauthenticated");
        }
        const userId = identity.subject;
        return await ctx.db.query("objects")
            .withIndex("by_user", (q) => q.eq("user", userId))
            .collect();
    },
});


Convex dev is running and says everything is ready. What's going on here? It's all [x: string]: any

Imports
import { useQuery } from "convex/react";
import { api } from "../../../../convex/_generated/api";
CleanShot_2025-01-09_at_19.19.442x.png
Was this page helpful?