empty attributes on ts models with target equal or above ES2022
cyjake opened this issue · comments
Chen Yangjian commented
class Template extends Bone {
@Column()
id: number;
@Column()
createdAt: Date;
}
the model above might be instantiated like an empty object when compiled with tsconfig that has target
set to ES2022 or above:
Collection (30) [
Template {}, ...
]
this is because public class fields will be initialized with [[Define]] rather than [[Set]] when the target is ES2022 or above. ts projects with this config will have to change the https://www.typescriptlang.org/tsconfig#useDefineForClassFields property to false.
JimmyDaddy commented
Or use declare
to define a column
class Base extends Bone {
@Column()
declare id: bigint;
}
class Note extends Base {
@Column()
declare body: string;
}