Typescript CreationAttributes are always being marked as optional with strictNullChecks disabled
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- api
Research direction
No repository files or tests are identified. Start by reproducing the supplied Sequelize model example with TypeScript 4.5.4 and strictNullChecks disabled, then trace the creation-attribute typings involved in Model creation. Done means omitting required name or height produces a TypeScript error while the optional id remains allowed.
Written by the indexing model from the issue text.
Description
Issue Creation Checklist
- I have read the contribution guidelines
Bug Description
Typescript CreationAttributes are being marked as optional regardless of actually marking them as so. When creating a model typescript does not complain about some required parameters that are missing because of this.
Example
import { DataTypes, Model, Optional, Sequelize } from "sequelize"
interface Attributes {
id: string
name: string
height: number
}
type CreationAttributes = Optional<Attributes, "id">
export default class Person extends Model<Attributes, CreationAttributes> implements Attributes {
public id!: string
public name!: string
public height!: number
public static initialize(sequelize: Sequelize) {
this.init({
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
field: "ID",
primaryKey: true,
allowNull: false,
},
name: {
type: DataTypes.STRING,
field: "Name",
allowNull: false,
},
height: {
type: DataTypes.NUMBER,
field: "Height",
allowNull: false,
}
}, {
sequelize: sequelize,
tableName: "Person"
})
}
}
What do you expect to happen?
It should throw a typescript error if Person.name and Person.height are not provided when creating a Person.
What is actually happening?
Typescript thinks name is optional even though it's being marked as required.

Typescript does not complain when required fields are omitted.

Environment
- Sequelize version: sequelize@6.18.0
- Node.js version: v14.19.1
- ITypeScript version: typescript@4.5.4
Would you be willing to resolve this issue by submitting a Pull Request?
- No, I don't have the time, although I believe I could do it if I had the time...
- Dominant language
- HTML
- Stars
- 30
- Forks
- 170
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sequelize/website
-
Difficulty 1/5 1-3 hours Newbie friendliness 74/100
-
Update Migration.md Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 55/100
All issues in sequelize/website
Similar issues
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100