omerbargon
omerbargon
WWasp-lang
Created by omerbargon on 10/3/2024 in #🙋questions
TypeScript Error: Property 'pages' Does Not Exist on Story Type
I’m working with the getGeneratedStories function, and I’ve included the pages in the query like this:
export const getGeneratedStories: GetGeneratedStories<void, Story[]> = async ( _args, context, ) => { if (!context.user) { throw new HttpError(401); } const stories = await context.entities.Story.findMany({ where: { userId: context.user.id, deletedAt: null, }, include: { pages: true, }, }); return stories; };
However, when I try to access story.pages in my component, I get a TypeScript error stating that the property 'pages' does not exist on type. The code works fine at runtime, but I can't seem to get TypeScript to recognize the pages property. Here’s how I’m trying to access it:
{stories.map((story) => { const isDisabled = story.status === "pending" || story.status === "generating"; // TypeScript error here const pageCount = story?.pages?.length || 0; return ( <></> ); })}
Could anyone help me understand why this TypeScript error occurs and how I can fix it? Thanks in advance! The Story model already includes the pages field in the Prisma schema
5 replies