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): Allow augmentation on model interfaces #11882

Merged
merged 1 commit into from
Feb 7, 2020

Conversation

hhhonzik
Copy link

@hhhonzik hhhonzik commented Jan 28, 2020

Written export instead of star export for Model declarations to allow module augmentation

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 extending any Model interface is ignored, due to specific Typescript behaviour

This PR enables full usage of augmentation on Model interfaces like this:

declare module 'sequelize' {
  export interface CreateOptions {
    auditLog?: ...;
  }
}

Example demo repository is here

Written export instead of star export for Model declarations to allow module augmentation
@codecov
Copy link

codecov bot commented Jan 28, 2020

Codecov Report

Merging #11882 into v5 will decrease coverage by 0.4%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##               v5   #11882      +/-   ##
==========================================
- Coverage   96.27%   95.87%   -0.41%     
==========================================
  Files          94       91       -3     
  Lines        9187     8984     -203     
==========================================
- Hits         8845     8613     -232     
- Misses        342      371      +29
Impacted Files Coverage Δ
lib/dialects/mariadb/query-generator.js 14.28% <0%> (-85.72%) ⬇️
lib/dialects/mariadb/data-types.js 50.98% <0%> (-49.02%) ⬇️
lib/query-interface.js 90.73% <0%> (-1.47%) ⬇️
lib/sequelize.js 95.32% <0%> (-0.63%) ⬇️
lib/dialects/mariadb/index.js
lib/dialects/mariadb/connection-manager.js
lib/dialects/mariadb/query.js

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 81c33d8...e517277. Read the comment docs.

@hhhonzik
Copy link
Author

Btw I've took all the exports from lib/model.d.ts file, maybe just a handpicked ones that are probably the most used could be enough.

export * from './lib/model';
export {
  CreateOptions,
  UpdateOptions,
  UpsertOptions,
  BulkCreateOptions,
  BuildOptions,
  Model,
  ModelType,
 } from './lib/model';

@hhhonzik
Copy link
Author

Also possible current workaround - you can override types like this:

// sequelize-fix.d.ts
declare module 'sequelize' {
  export * from 'sequelize/types';

  export {
    Model,
    BulkCreateOptions,
    UpdateOptions,
    InstanceUpdateOptions,
    CreateOptions,
  } from 'sequelize/types/lib/model';
}


// sequelize.d.ts
import 'sequelize';

declare module 'sequelize' {
  interface BulkCreateOptions {
    metadata?: any;
  }
}

@papb
Copy link
Member

papb commented Jan 31, 2020

Hello! I see you are a first-time contributor, thank you for taking the time to help Sequelize! I hope to see more PRs from you in the future!

Let's wait for @SimonSchick :)

@papb papb added status: awaiting maintainer type: typescript For issues and PRs. Things that involve typescript, such as typings and intellisense. labels Jan 31, 2020
@SimonSchick
Copy link
Contributor

They can already be augmented as is but I don't see harm in exporting them from root regardless.

@sushantdhiman sushantdhiman merged commit 43a8d61 into sequelize:v5 Feb 7, 2020
@sushantdhiman
Copy link
Contributor

🎉 This PR is included in version 5.21.4 🎉

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