fix(types): use correct `this` value when initializing getterMethods by schmod · Pull Request #11292 · sequelize/sequelize · GitHub
Skip to content

fix(types): use correct this value when initializing getterMethods#11292

Merged
sushantdhiman merged 1 commit into
sequelize:masterfrom
schmod:genericize-getters
Aug 9, 2019
Merged

fix(types): use correct this value when initializing getterMethods#11292
sushantdhiman merged 1 commit into
sequelize:masterfrom
schmod:genericize-getters

Conversation

@schmod

@schmod schmod commented Aug 7, 2019

Copy link
Copy Markdown
Contributor

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you update the typescript typings accordingly (if applicable)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Currently, if I try to initialize getterMethods or setterMethods while initializing a model in a TypeScript project, TS does not infer the correct type for this inside of those methods (and does not allow this to be easily casted to the correct type):

import { Association, HasOne, Model, Sequelize, DataTypes } from 'sequelize';

class MyModel extends Model {
  public num!: number;
}

MyModel.init({}, {
  sequelize,
  tableName: 'my_model',
  getterMethods: {
    multiply: function() {
      return this.num * 2; // <-- ERROR
    }
  }
});

@codecov

codecov Bot commented Aug 7, 2019

Copy link
Copy Markdown

@papb papb requested a review from SimonSchick August 7, 2019 16:10
@papb papb added status: awaiting maintainer typescript For issues and PRs. Things that involve typescript, such as typings and intellisense. labels Aug 7, 2019

@SimonSchick SimonSchick left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose.

@sushantdhiman sushantdhiman merged commit 98a4089 into sequelize:master Aug 9, 2019
@sushantdhiman

Copy link
Copy Markdown
Contributor

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

Labels

released typescript For issues and PRs. Things that involve typescript, such as typings and intellisense.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants