Skip to content

Type error passing unbound query helper to runtime query #706

@IlyaSemenov

Description

@IlyaSemenov

The new unbound ORM query helpers don't really work type-wise (orchid-orm 1.69.4). The code is as simple as:

const orm = bundleOrchidORMTables({
  user: UserTable,
})

const selectAuthUser = orm.user.makeHelper(
  q => q.select("name"),
)

const db = makeOrchidOrmDb(orm)

// Argument of type 'OrchidORMQueryHelper<TableToDb<UserTable>, [], SelectResult<TableToDb<UserTable>, ["name"]>>' is not assignable to parameter of type '(q: { relations: EmptyObject; definedAs: string; db: OrchidORM<TableClasses>; getFilePath: () => string; name: string; adapterNotInTransaction: Adapter; ... 195 more ...; window: <T extends Order.ArgThis, W extends WindowArg<T>>(this: T, arg: W) => WindowResult<...>; }) => SelectResult<...>'.
//   Types of parameters 'q' and 'q' are incompatible.
//     Type '{ relations: EmptyObject; definedAs: string; db: OrchidORM<TableClasses>; getFilePath: () => string; name: string; adapterNotInTransaction: Adapter; ... 195 more ...; window: <T extends Order.ArgThis, W extends WindowArg<T>>(this: T, arg: W) => WindowResult<...>; }' is not assignable to type 'TableToDb<UserTable>'.
//       Types of property 'returnType' are incompatible.
//         Type '"one"' is not assignable to type 'undefined'.
db.user.find(1).modify(selectAuthUser)
  • It works fine at runtime, it's only a type error.
  • It works fine if the very same helper is created with db.user.makeHelper, so it's specifically a regression with unbound helpers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions