-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(types): add missing transaction typescript types (v6-beta) #11620
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
Merged
sushantdhiman
merged 2 commits into
sequelize:master
from
aecorredor:fix/transaction-types
Oct 29, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, I have a question, I don't use TypeScript much, why is both an
enumand aninterfacenecessary? Also why is only theenumbeingexported?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also why did you move the enum outside the
export namespace Transactionblock?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, if sequelize was entirely written in TS (and not only types were provided), we could just use an
enumdirectly in the code and that would get compiled to an actual object (This is actually discouraged by some people and they advise to do this if you want to support runtime enums: https://medium.com/@martin_hotell/10-typescript-pro-tips-patterns-with-or-without-react-5799488d6680, look at point 3).But, since here we are just providing types and not touching the code, we can't just do that. Here, an
enumis just a TS type that basically says "look, whatever you say has this type, can only be one of these values". In our case,LOCKis anenumwith 4 possible values which we're saying are strings. Now, we might first think that thestatic get LOCKand theget LOCKwould return a type ofLOCK(which is an enum). But that would not be correct by looking at the code. The actual code returns an object with four properties,UPDATE,SHARE,KEY_SHAREandNO_KEY_UPDATE. So, for our types to be correct, we need to tellstatic get LOCKandget LOCKthat they return an object with those four properties, therefore the need for the interfaceLOCK, which models exactly that.We only export the
enumbecause we use it as one of the possible types forlockin themodelsfile. Theinterfaceis just used in this file to indicate what the getter functions return.I moved the
enumoutside the namespace because then it would conflict with the type declaration of the actual class getters also calledLOCK.