-
-
Notifications
You must be signed in to change notification settings - Fork 611
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
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
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working