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

TS error when tried to change createdAt, updatedAt columns type to something else #1705

Open
1 task
apudiu opened this issue Jan 23, 2024 · 1 comment
Open
1 task

Comments

@apudiu
Copy link

apudiu commented Jan 23, 2024

Issue

I want to override createdAt columns type from Date to DateTime(from Luxon). When I went to declare that getting TS error.

TS2612: Property createdAt will overwrite the base property in Model<any, any>. If this is intentional, add an initializer. Otherwise, add a declare modifier or remove the redundant declaration.

Versions

  • sequelize: 6.35.2,
  • sequelize-typescript: 2.1.6
  • typescript: 5.3.3

Issue type

  • [x ] bug report
  • feature request

Actual behavior

I'm working on Nest.js project & followed their docs

Expected behavior

Want to be able to override the type of createdAt, updatedAt & deletedAt columns data type

Steps to reproduce

On a fresh Nest.js project try to override/ change data type from Date to DateTime for those columns

Related code

// the model
export class User extends Model {
  @Column
  name: string;

  // ....

  @Column
  dob: DateTime;

  @Column
  refreshToken: string | null;

  @CreatedAt
  createdAt: DateTime;
// ^^^^^^^^ TS Err

  @UpdatedAt
  updatedAt: DateTime; 
// ^^^^^^^^ TS Err
}

// tsconfig
"compilerOptions": {
    "module": "CommonJS",
    "declaration": false,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "ES2022",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": true,
    "noImplicitAny": false,
    "strictBindCallApply": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
  }

// sequelize config
SequelizeModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (cs: ConfigService<AppConfig>) => {
        return { // this is the config
          dialect: 'mariadb',
          host: cs.get('db.host', { infer: true }),
          port: cs.get('db.port', { infer: true }),
          username: cs.get('db.user', { infer: true }),
          password: cs.get('db.pass', { infer: true }),
          database: cs.get('db.name', { infer: true }),
          models: [],
          autoLoadModels: true,
          synchronize: true,
          retryAttempts: 3,
          retryDelay: 500,
        };
      },
    })
@gugu
Copy link

gugu commented Apr 18, 2024

Upgrade from ES2021 to ES2022 causes this issue

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