adonisjs/lucid

FindManyBy return type error

Closed this issue · 2 comments

Package version

20.4.0

Describe the bug

Hello,

When trying to user findManyBy, for example:
const commissions = await Commission.findManyBy('userId', user.id)

the return type of commissions is:
LucidRow[] instend of Comission[]

like we have when doing classic findBy()

Reproduction repo

No response

I'm running into the same issue. You can fix it in user land by passing the type of your model as a type argument explicitly.

const commissions = await Commission.findManyBy<typeof Commision>('userId', user.id)

I'm unsure why the type is not inferred automatically correctly. Code looks pretty similar as the other lucid methods that work smoothly

findManyBy<T extends LucidModel>(

Yeah, we have to dig a bit this one, I will see if I have time tomorrow morning.