Skip to content

ModelStatic<M> looses custom static methods #18206

@ddolcimascolo

Description

@ddolcimascolo

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

ModelStatic TypeScript type looses custom satic methods.

Reproducible Example

const sequelize = ...; // Your Sequelize instance

class Foo extends Model {
  static myHelper(): Promise<Foo[]> {
    return this.findAll(...); // Custom logic, custom options, etc.
  }
}

Foo.init({}, { sequelize });

const F = sequelize.model('Foo') as ModelStatic<Foo>;

F.myHelper(); // TS2339: Property myHelper does not exist on type ModelStatic<Foo>

As a workaround you can type the return of sequelize.model) as typeof M instead.

What do you expect to happen?

The static helpers are kept in the ModelStatic type, and available.

What is actually happening?

The static helpers aren't available on the ModelStatic type.

Environment

  • Sequelize version: 6.37.8
  • Node.js version: 24.11.1
  • If TypeScript related: TypeScript version: 6.0.2
  • Database & Version: MySQL 8
  • Connector library & Version: mysql2@3.20.0

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending-approvalBug reports that have not been verified yet, or feature requests that have not been accepted yet

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions