Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
Accesorios opcionales en Mikro-orm

Estoy tratando de averiguar cómo definir propiedades opcionales adicionales.

 import { Entity, PrimaryKey, Property, OptionalProps } from '@mikro-orm/core'; @Entity() export abstract class BaseEntity { [OptionalProps]?: 'createdAt'; @PrimaryKey() id: number; @Property() createdAt: Date = new Date(); } @Entity() export class EntityA extends BaseEntity { [OptionalProps]?: 'isAnotherProperty'; // This is the bit I cannot figure out @Property() isAnotherProperty: boolean = false; }

Con el TypeScript anterior arroja un error:

 Property '[OptionalProps]' in type 'EntityA' is not assignable to the same property in base type 'BaseEntity'.

Básicamente, mi BaseEntity tiene propiedades opcionales, al igual que EntityA . ¿Podría eliminar [OptionalProps]?: de BaseEntity y tener [OptionalProps]?: 'createdAt' | 'isAnotherProperty'; en EntityA , pero muchas de mis entidades no requieren propiedades opcionales adicionales más allá createdAt , por lo que prefiero no tener que duplicar [OptionalProps]?: 'createdAt'; en cada clase de entidad si pudiera simplemente 'extenderlo' donde lo necesite.

¿Es posible agregar o anular [OptionalProps] ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Probablemente el enfoque más limpio es a través del argumento de tipo en la entidad base:

 import { Entity, PrimaryKey, Property, OptionalProps } from '@mikro-orm/core'; @Entity() export abstract class BaseEntity<O> { [OptionalProps]?: O | 'createdAt'; @PrimaryKey() id: number; @Property() createdAt: Date = new Date(); } @Entity() export class EntityA extends BaseEntity<'isAnotherProperty'> { @Property() isAnotherProperty: boolean = false; }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!