Abhishek
Abhishek10mo ago

How to extract types from schema if possible ?

export const getTrendingComics = query({
args: { id: v.string() },
handler: async (ctx) => {
const trendingComicsData: any = [];
const webData = await ctx.db.query("websiteContent").first();
const trendingComicsIdArray = webData?.trendingComics;
if (trendingComicsIdArray) {
await Promise.all(
trendingComicsIdArray.map(async (id) => {
const comic = await ctx.db.get(id);
trendingComicsData.push(comic);
})
);
}

return trendingComicsData;
},
});
export const getTrendingComics = query({
args: { id: v.string() },
handler: async (ctx) => {
const trendingComicsData: any = [];
const webData = await ctx.db.query("websiteContent").first();
const trendingComicsIdArray = webData?.trendingComics;
if (trendingComicsIdArray) {
await Promise.all(
trendingComicsIdArray.map(async (id) => {
const comic = await ctx.db.get(id);
trendingComicsData.push(comic);
})
);
}

return trendingComicsData;
},
});
How can I get the type of trendingComicsData from the schema ?
5 Replies
Abhishek
AbhishekOP10mo ago
comics: defineTable({
id: v.string(),
name: v.string(),
description: v.string(),
category: v.id("comicsCategories"),
tags: v.array(v.string()),
author: v.string(),
artist: v.string(),
})
comics: defineTable({
id: v.string(),
name: v.string(),
description: v.string(),
category: v.id("comicsCategories"),
tags: v.array(v.string()),
author: v.string(),
artist: v.string(),
})
this is the schema If there is a better another way of getting the type than please do help me thanks
jamwt
jamwt10mo ago
Doc<"comics"> is a document from the comics table so Doc<"comics">[] is probably the type you want here autocomplete on the table name and everything will work
jamwt
jamwt10mo ago
GitHub
convex-demos/node/convex/messages.ts at d4b6b97ce839ade881109653a6f...
Demo apps built on Convex. Contribute to get-convex/convex-demos development by creating an account on GitHub.
Abhishek
AbhishekOP10mo ago
Thanks @jamwt for the super quick response , its solved
sshader
sshader10mo ago
Types and Validators in TypeScript: A Convex Cookbook
It can be tough to wrangle types to behave how you want them to. Thankfully, Convex was designed to make the experience with types perfect. Learn why ...
TypeScript | Convex Developer Hub
Move faster with end-to-end type safety.

Did you find this page helpful?