PrismaP
Prisma14mo ago
7 replies
TJ

TypeScript error when using select argument type

Hi,
The following code snippet is working fine,
const results = await prisma.orders.findMany({
  select: {
    ...,
    products_orders_order_product_idToproducts: {
      select: {
        orders: {
          select: {
            clients: {
              select: {
                name: true,
              },
            },
          },
        },
      },
    },
  },
});
return results.map((row) => ({
  ...
  name:
    row.products_orders_order_product_idToproducts?.orders
      .clients?.name, // No TypeScript error
}));

and TypeScript started to complaint when I tried to extract the query options out to a options variable like this,
const options: Prisma.ordersFindManyArgs  = {
  select: {
    ...,
    products_orders_order_product_idToproducts: {
      select: {
        orders: {
          select: {
            clients: {
              select: {
                name: true,
              },
            },
          },
        },
      },
    },
  },
});

const results = await prisma.orders.findMany(options)
return results.map((row) => ({
  ...
  name:
    row.products_orders_order_product_idToproducts?.orders
      .clients?.name, // TypeScript error here 
}));

The error looks like this,
Property 'products_orders_order_product_idToproducts' does not exist on type { ... }

Do you have any idea how to resolve this?
Was this page helpful?