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

feat(types): Add ModelDefined type as syntactic sugar #12445

Merged
merged 6 commits into from Jul 4, 2020

Conversation

Keimeno
Copy link
Member

@Keimeno Keimeno commented Jun 30, 2020

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

The current way to define a module in a functional way with Typescript works like this:

const Note: ModelCtor<
  Model<
    NoteAttributes, 
    NoteCreationAttributes
  >
> = sequelize.define(
  ...
);

However this approach is a bit much to write, and with the ModelDefined type it could be reduced to:

const Note: ModelDefined<
  NoteAttributes, 
  NoteCreationAttributes
> = sequelize.define(
  ...
);

It's just added syntactic sugar, that simplifies things.
Also there is no reference to ModelCtor nor a functional way with Typescript in the docs.

So another change is, I've added an example for defining models in a functional way in Typescript.

@codecov
Copy link

codecov bot commented Jun 30, 2020

Codecov Report

Merging #12445 into v6 will decrease coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##               v6   #12445      +/-   ##
==========================================
- Coverage   96.44%   96.42%   -0.03%     
==========================================
  Files          95       95              
  Lines        9154     9154              
==========================================
- Hits         8829     8827       -2     
- Misses        325      327       +2     
Impacted Files Coverage Δ
lib/dialects/postgres/connection-manager.js 94.40% <0.00%> (-1.40%) ⬇️

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 945af92...d45f2b3. Read the comment docs.

@sushantdhiman
Copy link
Contributor

NOTE: Keep the following code in sync with typescriptDocs/ModelInit.ts to ensure it typechecks correctly.

Please take care of that

@Keimeno
Copy link
Member Author

Keimeno commented Jul 2, 2020

Is synchronized now. Also commented out the Notice about synchronization

@sushantdhiman sushantdhiman merged commit 5cabcbc into sequelize:v6 Jul 4, 2020
@sushantdhiman
Copy link
Contributor

🎉 This PR is included in version 6.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

jctaveras pushed a commit to jctaveras/sequelize that referenced this pull request Mar 29, 2021
@Keimeno Keimeno deleted the feature/model-definition-type branch May 26, 2021 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants