-
Notifications
You must be signed in to change notification settings - Fork 837
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
[Typescript] Moment types have been updated #982
Comments
As far as I can tell, these type errors are not caused by Moment Timezone itself. It's just that Moment Timezone is exposing an underlying problem: multiple versions of base Moment in the same project. I also got type errors like this in a project using Moment (but not Timezone) when we upgraded to In this case, when you load the default Why does this happen?It comes down to package version resolution when your project depends on a package, and other packages also depend on that package. Ideally they all use the exact same copy of that dependency, but sometimes multiple versions are needed to satisfy all the version range requirements. Or sometimes a single version could be used, but dependency upgrades over time have caused the dependencies to get out of sync. A simple example of including both
You want Most of the time, the two different versions don't cause much of a problem because they're fairly compatible. (Though if you're bundling for a front-end project, you now have 2 copies of Getting an object from (If your The best solution is to try to de-duplicate your copies of How to fix itMy experience is only with npmExpand for full detailsFirst, find out what versions of # Example
$ npm ls moment
mtz-ts-example@1.0.0 /path/to/project
├─┬ moment-timezone@0.5.34
│ └── moment@2.29.3
└── moment@2.29.1 If there's more than one version listed (like NOTE: $ npm dedupe
changed 1 package, and audited 4 packages
$ npm ls moment
mtz-ts-example@1.0.0 /path/to/project
├─┬ moment-timezone@0.5.34
│ └── moment@2.29.3 deduped
└── moment@2.29.3 YarnExpand for full detailsLike the # Using Yarn v1
$ yarn why moment
yarn why v1.22.17
[1/4] 🤔 Why do we have the module "moment"...?
[2/4] 🚚 Initialising dependency graph...
[3/4] 🔍 Finding dependency...
[4/4] 🚡 Calculating file sizes...
=> Found "moment@2.29.1"
info Has been hoisted to "moment"
info This module exists because it's specified in "dependencies".
info Disk size without dependencies: "5.14MB"
info Disk size with unique dependencies: "5.14MB"
info Disk size with transitive dependencies: "5.14MB"
info Number of shared dependencies: 0
=> Found "moment-timezone#moment@2.29.3"
info This module exists because "moment-timezone" depends on it.
info Disk size without dependencies: "5.16MB"
info Disk size with unique dependencies: "5.16MB"
info Disk size with transitive dependencies: "5.16MB"
info Number of shared dependencies: 0 The way to de-duplicate the versions depends on which version of Yarn you're using.
Review your importing strategyThe cases above are a very simplified version of a potentially very complex scenario. It's not always possible to neatly resolve version conflicts using tools and scripts. A few of the bug reports about TypeScript errors in Moment Timezone have included code samples like this: import 'moment-timezone';
import moment from 'moment'; import * as moment from 'moment';
import 'moment-timezone'; Importing both
This is why the Moment Timezone docs examples only import/require import moment from 'moment-timezone'; This means you could also remove the direct dependency on |
@gilmoreorless Your comment was super helpful. Thanks! |
Thank you @gilmoreorless, very professionally written and concise :) |
Moment-timezone version which you use:
Version:
0.5.34 (latest)
Issue description:
Original Moment types have been updated, in version 2.29.3, and due to that fact typescript complains:
temporary fix would be to do conversion to unknown first, but this should be fixed
The text was updated successfully, but these errors were encountered: