-
Notifications
You must be signed in to change notification settings - Fork 282
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
Loosen semver ranges on 3rd-party typings #166
Conversation
User | ||
.findOne({where: ['asdasdasd']}) | ||
.findOne<User>({where: <any>{ bad: 'asdasdasd' }}) |
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.
Incidentally, the newer Sequelize typings actually turn bad where
clauses into a compiler error, making this sort of error a bit harder to trigger.
username: 'cuss' | ||
}) | ||
where: { | ||
[sequelize.Op ? sequelize.Op.and : '$and']: { username: 'cuss' } |
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.
Awkward workaround to simultaneously support Sequelize v3 and v4.
@types/sequelize
for v4 allows some of the legacy operators, but not all of them (there might be a reason for it, but I can't find one). I'll send them a separate PR to fix that.
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.
In #157 the project decided to drop v3 support - however since that hasn't happened yet (in code), I'm not sure what the best course of action for this code is. For now what you have is probably good, since the codebase currently tries to support both - but when we drop v3 we can get rid of the awkward workaround.
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.
Yep, but as long as we've got tests targeting v3....
Codecov Report
@@ Coverage Diff @@
## master #166 +/- ##
==========================================
- Coverage 96.84% 96.63% -0.21%
==========================================
Files 100 100
Lines 918 921 +3
Branches 124 125 +1
==========================================
+ Hits 889 890 +1
- Misses 9 10 +1
- Partials 20 21 +1
Continue to review full report at Codecov.
|
|
||
return arg.reduce((models: any[], dir) => { | ||
|
||
if (typeof dir !== 'string') { |
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.
@RobinBuschmann do we have tests on this method? (I don't think I saw any in model.spec.ts
?) This would be good to have some tests. (array with Model and String elems / only string elems / only Model elems / empty array / null / object).
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.
@snewell92 No, we don't have any for this method only. @schmod Can you add some tests as a part of this PR? This would also increase coverage :)
@schmod Glad to have a new first time PR 😺I think it's golden, just not sure if we could add tests to increase coverage or not (hence ping to Robin), but Codecov has been known to be finicky about small things ¯\_(ツ)_/¯ @RobinBuschmann could you look over this when you can, just to look over the change in |
"@types/node": "6.0.41", | ||
"@types/reflect-metadata": "0.0.4", | ||
"@types/sequelize": "4.0.73", | ||
"@types/bluebird": "^3.5.15", |
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.
Let us keep the exact versions here. Here is a discussion about it: #142
Maybe we can get rid of setting the bluebird typings explicitly as a dependency, cause they are required by the sequelize typings anyway. What do you think, @snewell92 @schmod ? |
If we drop bluebird (and remove its use from |
@snewell92 Sequelize already uses Bluebird promises "out of the box", and the typings accurately reflect this. You should theoretically be able to do this already. Unfortunately, there have been "semver-minor" changes to Bluebird's typings that appear to be incompatible with each other, which is why this does not currently appear to work in many cases. Getting rid of the Bluebird typings probably won't be practical, unless we can explicitly import them from If we're maintaining a hard lock on a specific version of Given the recurrence of these issues, I think our docs need to explain this project's relationship with |
I think it makes sense to do what
A peer dependency! That sounds very reasonable. Now that I think about it... yes. That is exactly the relationship sequelize-typescript expects with sequelize (since it doesn't have a dep on sequelize, but won't work without it). |
Regarding bluebird: Hmm, I probably miss the point here or I was not clear enough. The bluebird typings will be installed anyway, cause they are a dependency of the sequelize typings. So there is nothing left to do... or maybe I don't understand what are you going to say? 😱 |
I don't think this is a great assumption to make. It might not always be true, and contradicts the conventions typically used by Node.JS projects -- I can't think of any projects that For example, this is a perfectly valid tree that NPM (or some other package manager) could produce:
In this example, the |
I can think of two scenarios, where this would happen: on an old node version or if the bluebird typings are already installed. Is there another one ? Anyway, you're absolutely right, an explicit solution is better. However I think we can omit the bluebird typings. Because the sequelize typings exports them. So that sequelize-typescript could use promises like this `import {Promise} from 'sequelize'; Do I miss something? |
Just revisiting - I still really like @schmod 's suggestion of a peer dep to sequelize, and matching bluebird typings to what @types/sequelize lists, and of course matching bluebird to what sequelize lists too, so that when we bump a sequelize version, we then must match bluebird and its typings for the appropriate version of sequelize we're bumping up too. This will ensure correctness in our types. @RobinBuschmann I think your two scenarios fail to capture the complexity of npm's package system. There are a lot of different scenarios:
Then consider, in the dependency tree, since sequelize installs bluebird too, if our bluebird and its types match sequelize's, and if either of those (sequelize or our's) match the root import. Not to mention if there are other packages that may or may not wrap, call into, or use sequelize/sequelize-typescript (like Thus we reach a combinatorial explosion of cases. (I think) The typescript compiler can get the appropriate types at each level, but the problem is that if bluebird introduces some breaking change, and if sequelize or sequelize-typescript call into their own copy of bluebird down the dep tree - then typescript might report something that doesn't actually exist (since at the root, bluebird is available), or an API has changed and won't work as expected. I'm not actually sure how this would work, and am interested in a deeper case study, but I don't think that's necessary to get to a conclusion here. Now, I can see how just dropping bluebird might seem to sidestep the issue, but then it's just another subtle problem, because we wrap sequelize and our code base calls into sequelize, we wouldn't be exposing the actual real type of the promises that sequelize returns, and if we ever create a promise to do work, it could (would it have to be?) be native instead of bluebird, which would mix promise types. Again, not 100% on all that, but just thinking about it makes me squirm. @schmod if I've mistakenly analyzed anything, please rebuketh me! #learning #discussion => keep bluebird, match its version to sequelize |
Ok, lets define an explicit dependency of |
Good question. If we list bluebird as a peer dep, we force the user to use bluebird. Since Just an example package.json so I can wrap my head around it more: package.json snippet "dependencies": {
"@types/sequelize": "^4.0.76",
"bluebird": "^3.4.6",
"@types/bluebird": "^3.5.5"
},
"peerDependencies": {
"sequelize": "4.22.6"
}, @schmod @RobinBuschmann perhaps our |
I honestly don't see a problem being somewhat permissive with the version ranges of our
|
Ah, okay. So something like this: package.json snippet: "dependencies": {
"bluebird": "3.4.6",
"@types/bluebird": "3.5.15",
"@types/sequelize": "4.0.76"
},
"peerDependencies": {
"sequelize": "~4.22.0"
} What do y'all think? 👍 for ya, 😕 for wat |
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.
Change package.json
as per our consensus. Then LGTM 😀
Just this week I've noticed this tsc feature: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types So my question: Should we use this and put the type dependencies ( |
I sort have used I'd be interested to see how typescript handles several cases, I might have time to play with this kind of stuff next week. I would try by specifying the type roots, and then specifying no type roots, and having a consuming project both match and then not match the bluebird / sequelize typings - just to see what happens. I don't think the use of |
This would be nice :)
Wasn't intended to be a fix for this issue. Probably not the right place to mention this feature. |
With version |
Fixes #165, and possibly some other issues that may result from this project using a slightly older version of
@types/sequelize
and typescript.Due to one of these updates, the behavior of
getModels()
had to be slightly modified to conform with its type signature. This should not be a breaking change for anybody.Also fixed up a few tests that were using strange (and seemingly undocumented) variations of the
where:
operator.