I am trying to fetch data from mysql2 using nextjs and typescript is complaining about my query

33 Views Asked by At

const { appointmentnumber } = ( await db.execute( SELECT COUNT(appointmentdate) + 1 AS appointmentnumber FROM appointment WHERE appointmentdate = ?, [body.date] ) )[0];

Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'OkPacket | RowDataPacket[] | ResultSetHeader[] | RowDataPacket[][] | OkPacket[] | ProcedureCallPacket'. Property '0' does not exist on type 'OkPacket | RowDataPacket[]

i tried setting it as any like:

const body = await request.json();

const { appointmentnumber } = (
  await db.execute(
    `SELECT COUNT(appointmentdate) + 1 AS appointmentnumber FROM appointment WHERE appointmentdate = ?`,
    [body.date]
  )
)as any[0];

but if i do that my result will be undefined

0

There are 0 best solutions below