No typesaftey for dynamic returns

// BE
publicProcedure.input(z.object({shouldPopulateRelation: z.boolean()})).query(({ input, ctx }) => {
return ctx.db.thing.findMany({ include: input.shouldPopulateRealtion })
})

// FE
const {data} = api.thing.useQuery({shouldPopulateRelation: false})

data.relation // exists when it shouldn't
// BE
publicProcedure.input(z.object({shouldPopulateRelation: z.boolean()})).query(({ input, ctx }) => {
return ctx.db.thing.findMany({ include: input.shouldPopulateRealtion })
})

// FE
const {data} = api.thing.useQuery({shouldPopulateRelation: false})

data.relation // exists when it shouldn't
Even more concerning is that the data.relation field isn't even optional which is surely an error
1 Reply
Neto
Neto9mo ago
ts isnt able to generate runtime types like that
Want results from more Discord servers?
Add your server