NEEGHAN
NEEGHAN
Explore posts from servers
CCConvex Community
Created by NEEGHAN on 4/27/2025 in #support-community
`useQuery` returning type `never`
No noticeable drawbacks
13 replies
CCConvex Community
Created by NEEGHAN on 4/27/2025 in #support-community
`useQuery` returning type `never`
Update: it started working once I disabled TS project references for the convex project (@nx/convex which contained Convex code and was being imported from by @ns/nextjs-app which contained Next.js app code). So I set "composite", "declarationMap" and "emitDeclarationOnly" to false in the project's tsconfigs and dereferenced the project everywhere else (removed from "references" of root tsconfig and the Next.js app's tsconfig).
13 replies
CCConvex Community
Created by NEEGHAN on 4/27/2025 in #support-community
`useQuery` returning type `never`
Another interesting thing is that when running tsc --build for the Next.js app project, I get a type error
const messages = useQuery(api.chat.getMessages);
// ^
// error TS2339: Property 'chat' does not exist on type '{}'.
const messages = useQuery(api.chat.getMessages);
// ^
// error TS2339: Property 'chat' does not exist on type '{}'.
which doesn't show up in the editor. So there's inconsistency between tsc and editor integration as well. (FYI, I have set up "typescript.tsdk" to point to node_modules TS SDK.) So at compile-time, TypeScript seems to think api is just an empty object??
13 replies
CCConvex Community
Created by NEEGHAN on 4/27/2025 in #support-community
`useQuery` returning type `never`
No description
13 replies
CCConvex Community
Created by NEEGHAN on 4/27/2025 in #support-community
`useQuery` returning type `never`
No description
13 replies
CCConvex Community
Created by NEEGHAN on 4/27/2025 in #support-community
`useQuery` returning type `never`
Yeah, I tried those things as well (nuking node_modules, restarting TS language server) but it didn't help 😅
13 replies
CCConvex Community
Created by NEEGHAN on 4/27/2025 in #support-community
`useQuery` returning type `never`
For context, here's the schema.ts:
import {defineSchema, defineTable} from "convex/server";
import {type Infer, v} from "convex/values";

export const roleValidator = v.union(v.literal("user"), v.literal("assistant"));

export type ChatMessageRole = Infer<typeof roleValidator>;

export default defineSchema({
chat_messages: defineTable({
user: v.string(),
role: roleValidator,
content: v.optional(v.string()),
stream: v.optional(v.string()),
}).index("by_user", ["user"]),
});
import {defineSchema, defineTable} from "convex/server";
import {type Infer, v} from "convex/values";

export const roleValidator = v.union(v.literal("user"), v.literal("assistant"));

export type ChatMessageRole = Infer<typeof roleValidator>;

export default defineSchema({
chat_messages: defineTable({
user: v.string(),
role: roleValidator,
content: v.optional(v.string()),
stream: v.optional(v.string()),
}).index("by_user", ["user"]),
});
13 replies
CCConvex Community
Created by NEEGHAN on 4/27/2025 in #support-community
`useQuery` returning type `never`
FYI, if I import dataModel.d.ts in the Next.js app, the Doc type also resolves to never:
{
"name": "@ns/convex",
...
"exports": {
...
"./dataModel": "./src/_generated/dataModel.d.ts"
}
}
{
"name": "@ns/convex",
...
"exports": {
...
"./dataModel": "./src/_generated/dataModel.d.ts"
}
}
// in packages/nextjs-app/src/components/Chat.tsx
import {type Doc} from "@ns/convex/dataModel";
// ^
// TypeScript resolves this as
// type Doc<TableName extends TableNames> = {
// chat_messages: never;
// }[TableName]["document"]
// in packages/nextjs-app/src/components/Chat.tsx
import {type Doc} from "@ns/convex/dataModel";
// ^
// TypeScript resolves this as
// type Doc<TableName extends TableNames> = {
// chat_messages: never;
// }[TableName]["document"]
13 replies
CCConvex Community
Created by NEEGHAN on 4/27/2025 in #support-community
`useQuery` returning type `never`
Same happens if I explicitly type messages or handler:
// in packages/convex/src/chat.ts
export const getMessages = query({
handler: async (ctx): Promise<Doc<"chat_messages">[]> => {
const messages = await ctx.db.query("chat_messages").collect();
return messages;
},
});
// in packages/convex/src/chat.ts
export const getMessages = query({
handler: async (ctx): Promise<Doc<"chat_messages">[]> => {
const messages = await ctx.db.query("chat_messages").collect();
return messages;
},
});
// in packages/convex/src/chat.ts
export const getMessages = query({
handler: async (ctx) => {
const messages: Doc<"chat_messages">[] = await ctx.db.query("chat_messages").collect();
return messages;
},
});
// in packages/convex/src/chat.ts
export const getMessages = query({
handler: async (ctx) => {
const messages: Doc<"chat_messages">[] = await ctx.db.query("chat_messages").collect();
return messages;
},
});
But if the type doesn't use anything that comes from the data model (schema), then it weirdly enough works:
// in packages/convex/src/chat.ts
export const getMessages = query({
handler: async (ctx) => {
const messages = await ctx.db.query("chat_messages").collect();
// has to be cast to unknown first since here it still manages to infer the type correctly
return messages as unknown as {customType: string}[];
},
});
// in packages/convex/src/chat.ts
export const getMessages = query({
handler: async (ctx) => {
const messages = await ctx.db.query("chat_messages").collect();
// has to be cast to unknown first since here it still manages to infer the type correctly
return messages as unknown as {customType: string}[];
},
});
// in packages/nextjs-app/src/components/Chat.tsx
export const Chat = () => {
const messages = useQuery(api.chat.getMessages);
// ^
// TypeScript infers this to `{customType: string}[] | undefined`
...
};
// in packages/nextjs-app/src/components/Chat.tsx
export const Chat = () => {
const messages = useQuery(api.chat.getMessages);
// ^
// TypeScript infers this to `{customType: string}[] | undefined`
...
};
13 replies
TTCTheo's Typesafe Cult
Created by NEEGHAN on 2/1/2023 in #questions
How well can I rely on Tailwinds ability to know what classes to include in the CSS?
So does it perform a simple search on each file to find the class names or is it a more intricate process that involves analyzing the AST? For example, if I write a complete class name in a comment or in an unused variable, will it still include that class name or will it know that it doesn't have to include that class name?
7 replies
TTCTheo's Typesafe Cult
Created by NEEGHAN on 2/1/2023 in #questions
How well can I rely on Tailwinds ability to know what classes to include in the CSS?
Okay. Thanks!
7 replies
TTCTheo's Typesafe Cult
Created by NEEGHAN on 9/30/2022 in #questions
Many-to-many relationship in SQL as table or JSONB array?
So I was considering object columns mainly for the convenience of in the client being able to fetch games (select * from games through PostgREST) and receiving objects where players is an array of player ids. Now if I want to get objects shaped like that in the client, I’d have to built an endpoint which makes many underlying queries.
9 replies
TTCTheo's Typesafe Cult
Created by NEEGHAN on 9/30/2022 in #questions
Many-to-many relationship in SQL as table or JSONB array?
Yes I will! Do you have any resources (videos, articles) on the topic that you’d especially recommend?
9 replies