romeerez / orchid-orm

Orchid ORM
https://orchid-orm.netlify.app/
MIT License
482 stars 14 forks source link

Typescript `never` when doing nested selects #322

Closed mordechaim closed 3 weeks ago

mordechaim commented 4 weeks ago

When selecting a relation 3 levels deep, using the '*' keyword, the return type is marked never:


const result = await db.one.select('*', {
  two: (q) =>
    q.two.select('*', {
      three: (q) => q.three.select('*'),
    }),
});

Will have types as:

const result: {
    two: never;
    id: number;
    test: string;
    twoId: number | null;
}[]

You can find a reproduction here

mordechaim commented 4 weeks ago

I edited the issue, the first problem isn't related to it, as you can't select relations in a create.

Actually, is there a way to do it?

romeerez commented 3 weeks ago

I published a fix, thanks for a reproduction!

When nothing is selected, all is selected by default, and if you'd remove the inner select('*'), the type would be ok.

you can't select relations in a create. Actually, is there a way to do it?

Currently, no, so you can only load related data in a separate query. It would be very nice to have feature, to select relations on create and update, I'll try to add it in not so distant future.

mordechaim commented 3 weeks ago

Thanks

When nothing is selected, all is selected by default

I know, I wanted to select a computed field which isn't included by default