镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Handling timestamp fields in Typescript #561

Open

Description

@Maiquu

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 });

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions