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

Handling timestamp fields in Typescript #561

Open
Maiquu opened this issue Aug 22, 2023 · 0 comments
Open

Handling timestamp fields in Typescript #561

Maiquu opened this issue Aug 22, 2023 · 0 comments

Comments

@Maiquu
Copy link

Maiquu commented Aug 22, 2023

Issue Description

Issue is regarding this section.
Silencing typing errors regarding timestamps via specifying them in init method changes the created table schema. By default, timestamp fields created by sequelize are non nullable, but when we specify them to silence the error, timestamps are created as nullable fields.

Snippet:

Timestamp attributes managed by Sequelize (by default, createdAt, updatedAt, and deletedAt) don't need to be configured using Model.init, unfortunately Model.init has no way of knowing this. We recommend you use the minimum necessary configuration to silence this error:

User.init({
  // technically, `createdAt` & `updatedAt` are added by Sequelize and don't need to be configured in Model.init
  // but the typings of Model.init do not know this. Add the following to mute the typing error:
  createdAt: DataTypes.DATE,
  updatedAt: DataTypes.DATE,
}, { sequelize });

What was unclear/insufficient/not covered in the documentation

Current documentation misleads the user into thinking that specifying timestamp fields, does not affect runtime behavior, and is only to silence typescript.

If possible: Provide some suggestion on how we can enhance the docs

I'm not sure if this is a documentation or code error, but it if the problem is on documentation side, it should be fixed as

User.init({
  // ...
  createdAt: { type: DataTypes.DATE, allowNull: false },
  updatedAt: { type: DataTypes.DATE, allowNull: false },
}, { sequelize });
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

1 participant