adonisjs / lucid

AdonisJS SQL ORM. Supports PostgreSQL, MySQL, MSSQL, Redshift, SQLite and many more
https://lucid.adonisjs.com/
MIT License
1.07k stars 191 forks source link

FindManyBy return type error #1014

Closed corentinclichy closed 6 months ago

corentinclichy commented 6 months ago

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

CodingDive commented 6 months ago

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

RomainLanz commented 6 months ago

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