Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty attributes on ts models with target equal or above ES2022 #377

Open
cyjake opened this issue Mar 16, 2023 · 1 comment
Open

empty attributes on ts models with target equal or above ES2022 #377

cyjake opened this issue Mar 16, 2023 · 1 comment

Comments

@cyjake
Copy link
Owner

cyjake commented Mar 16, 2023

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.

@cyjake cyjake pinned this issue May 10, 2023
@JimmyDaddy
Copy link
Collaborator

Or use declare to define a column

class Base extends Bone {
  @Column()
  declare id: bigint;
}

class Note extends Base {
  @Column()
  declare body: string;
}

@coinkits coinkits unpinned this issue Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants