Ragpud
Ragpud
CCConvex Community
Created by Ragpud on 2/5/2025 in #support-community
Can I use "skip" with zQuery?
I'm trying to get a files metadata if a file id exists and "skip" would be perfect for that use case. When inspecting useQuery I can pass skip, but when I try it throws an error because of my zod schema in the query definition. Is there a workaround for this?
const fileWithData = useQuery(
api.files.getFile,
stagedImageId
? {
storageId: stagedImageId || "",
}
: "skip"
);
const fileWithData = useQuery(
api.files.getFile,
stagedImageId
? {
storageId: stagedImageId || "",
}
: "skip"
);
zQuery definition
export const zQuery = zCustomQuery(query, NoOp);
export const zQuery = zCustomQuery(query, NoOp);
Error
Argument of type '"skip" | { storageId: string | Id<"_storage">; }' is not assignable to parameter of type '{ storageId: string & { __tableName: "_storage"; }; } | "skip"'.
Type '{ storageId: string | Id<"_storage">; }' is not assignable to type '{ storageId: string & { __tableName: "_storage"; }; } | "skip"'.
Types of property 'storageId' are incompatible.
Type 'string | Id<"_storage">' is not assignable to type '(string & { __tableName: "_storage"; }) | undefined'.
Type 'string' is not assignable to type 'string & { __tableName: "_storage"; }'.
Type 'string' is not assignable to type '{ __tableName: "_storage"; }'
Argument of type '"skip" | { storageId: string | Id<"_storage">; }' is not assignable to parameter of type '{ storageId: string & { __tableName: "_storage"; }; } | "skip"'.
Type '{ storageId: string | Id<"_storage">; }' is not assignable to type '{ storageId: string & { __tableName: "_storage"; }; } | "skip"'.
Types of property 'storageId' are incompatible.
Type 'string | Id<"_storage">' is not assignable to type '(string & { __tableName: "_storage"; }) | undefined'.
Type 'string' is not assignable to type 'string & { __tableName: "_storage"; }'.
Type 'string' is not assignable to type '{ __tableName: "_storage"; }'
3 replies
CCConvex Community
Created by Ragpud on 3/12/2024 in #support-community
Ents + Server components
Hello 👋 I'm using convex with NextJS and the preloadQuery and fetchQuery methods are working great for me. The only thing I can see getting in my way a the moment is the Ents types. In the docs it says you can specify a prop from a server component with:
preloadedTasks: Preloaded<typeof api.tasks.list>;
preloadedTasks: Preloaded<typeof api.tasks.list>;
However when using Ents the return type of queries doesn't equal Preloaded<typeof api.tasks.list>. I can't see anything in the Ents docs about this. So what I'm asking is: is what I'm trying to do not possible, not been tried before yet or just not documented yet? I reckon the answer lies in just a fancy typescript type, although unfortunately I'm not good enough with typescript yet to figure it out.
6 replies