sequelize / sequelize/sequelize
Sequelize v6.x.x model definition by extending Model class with TypeScript v5.x.x issue
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 30.4k
- Forks
- 4.3k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 68
Description
Issue Creation Checklist
- I understand that my issue will be automatically closed if I don't fill in the requested information
- I have read the contribution guidelines
Bug Description
Sequelize v6 model definition by extending Model class using TypeScript v5.x.x results in tsc compilation errors:
- Method 'set' in class 'X' is not assignable to the same method in base 'Model'
- Method 'setAttributes' in class 'X' is not assignable to the same method in base 'Model'
where class X is model being defined using inheritance.
Same tsc compilation errors occur when using the sequelize-typescript v2.x.x and TypeScript v5.x.x..
Warnings are raised when using Sequelize v7.x.x and TypeScript v5.x.x.
Reproducible Example
Here is the link to the SSCCE for this issue: https://github.com/oglisa-dev/sequelize-typescript-v5-issue-sscce
What do you expect to happen?
Arbitrary model X should be defined by extending Model class without any tsc compilation errors when using Sequelize v6.x.x and TypeScript v5.x.x.
Arbitrary model X should be defined by extending Model class using sequelize-typescript without any tsc compilation errors when using sequelize-typescript v2.x.x and TypeScript v5.x.x.
Arbitrary model X should be defined by extending Model class without any warnings when using Sequelize v7.x.x and TypeScript v5.x.x.
What is actually happening?
// using sequelize v6
import { DataTypes, Model, Sequelize } from "sequelize";
// ts errors:
// Method 'set' in class 'User' is not assignable to the same method in base 'Model'
// Method 'setAttributes' in class 'User' is not assignable to the same method in base 'Model'
export class User extends Model {
declare firstname: string;
declare lastname: string;
}
// using sequelize-typescript v2
import { Table, Column, Model } from 'sequelize-typescript';
// ts errors
// Method 'set' in class 'Person' is not assignable to the same method in base 'Model'
// Method 'setAttributes' in class 'Person' is not assignable to the same method in base 'Model'
@Table
export class Person extends Model {
@Column
firstname: string;
@Column
lastname: Date;
}
// using sequelize v7
import {CreationOptional, DataTypes, InferAttributes, InferCreationAttributes, Model} from '@sequelize/core';
import { Attribute, PrimaryKey, AutoIncrement, NotNull } from '@sequelize/core/decorators-legacy';
// warnings (not errors)
// Method 'set' in class 'User' is not assignable to the same method in base 'Model'
// Method 'setAttributes' in class 'User' is not assignable to the same method in base 'Model'
export class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
@Attribute(DataTypes.INTEGER)
@PrimaryKey
@AutoIncrement
declare id: CreationOptional<number>;
@Attribute(DataTypes.STRING)
@NotNull
declare firstName: string;
@Attribute(DataTypes.STRING)
declare lastName: string | null;
}
Environment
- Sequelize version: v6.33.0
- Node.js version: v20.7.0
- TypeScript version: v5.2.2
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I will need guidance.
- No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
- No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in resolving my issue.
Indicate your interest in the resolution of this issue by adding the 👍 reaction. Comments such as "+1" will be removed.
Contributor guide
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.
Research direction
Start with the linked SSCCE repository and reproduce the TypeScript 5 compilation errors for the Sequelize v6 model examples. Then inspect the Model class definitions involved in set and setAttributes, comparing the v6, sequelize-typescript v2, and Sequelize v7 cases. Done means the examples compile without errors or warnings under the stated versions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100