lucid icon indicating copy to clipboard operation
lucid copied to clipboard

FindManyBy return type error

Open corentinclichy opened this issue 11 months ago • 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

corentinclichy avatar Mar 16 '24 20:03 corentinclichy

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 https://github.com/adonisjs/lucid/blob/196c97c580b0f5327f6330f8b799169f02571adc/src/types/model.ts#L1001

CodingDive avatar Mar 24 '24 22:03 CodingDive

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

RomainLanz avatar Mar 24 '24 23:03 RomainLanz