Skip to content

Non-useful type for 'where' argument for @Entity decorator expression callback #6481

@rcfox

Description

@rcfox

Describe the bug

Version 6.4.7 seems to have added some improved typing around entities. However, when creating a virtual entity using a callback expression, the where argument seems to be incorrect, or at least not useful. None of the fields are accessible because it appears to be checking typeof MyEntity instead of MyEntity.

My project has been extracting fields from the where argument to compose a dynamic query, and so this is preventing us from upgrading.

When inspecting the type of the @Entity decorator on a standard non-virtual entity, I can see that the resolved generic type is Entity<typeof MyEntity>. Is that expected?

Reproduction

@Entity({
  expression: (em: EntityManager, where, options) => {
    // As of Mikro-ORM v6.4.7:
    // type of `where` is FilterQuery<typeof Test>
    // Property 'foo' does not exist on type 'FilterQuery<typeof Test>'.
    //  Property 'foo' does not exist on type 'typeof Test'. [2339]
    return [{ foo: where.foo }];
  },
})
export class Test {
  @Property()
  foo!: string;
}

...

// In Mikro-ORM v6.4.6, this used to work:
const test = await this.em.find(Test, {foo: 'a'})
console.log(test) // [ Test { foo: 'a' } ]

What driver are you using?

@mikro-orm/postgresql

MikroORM version

6.4.7, 6.4.8

Node.js version

v22.14.0

Typescript version

v5.4.5

Operating system

Ubuntu Linux

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions