Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Aug 9, 2019

Conversation

schmod
Copy link
Contributor

@schmod schmod commented Aug 7, 2019

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
Copy link

codecov bot commented Aug 7, 2019

Codecov Report

Merging #11292 into master will increase coverage by 0.76%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #11292      +/-   ##
==========================================
+ Coverage   95.58%   96.34%   +0.76%     
==========================================
  Files          91       94       +3     
  Lines        8855     9057     +202     
==========================================
+ Hits         8464     8726     +262     
+ Misses        391      331      -60
Impacted Files Coverage Δ
lib/dialects/mariadb/index.js 100% <0%> (ø)
lib/dialects/mariadb/connection-manager.js 100% <0%> (ø)
lib/dialects/mariadb/query.js 87.87% <0%> (ø)
lib/dialects/abstract/query-generator.js 97.61% <0%> (+0.17%) ⬆️
lib/sequelize.js 95.95% <0%> (+0.62%) ⬆️
lib/query-interface.js 92.17% <0%> (+1.46%) ⬆️
lib/dialects/mariadb/data-types.js 100% <0%> (+49.01%) ⬆️
lib/dialects/mariadb/query-generator.js 97.87% <0%> (+87.23%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 488c048...4be2afd. Read the comment docs.

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

@SimonSchick SimonSchick left a comment

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
Contributor

🎉 This PR is included in version 5.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released type: 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.

None yet

4 participants