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

[TypeScript] moment 2.29.3 Property 'tz' does not exist on type 'typeof moment' #981

Closed
AbdelrahmanHafez opened this issue Apr 18, 2022 · 7 comments

Comments

@AbdelrahmanHafez
Copy link

AbdelrahmanHafez commented Apr 18, 2022

Versions:

  • moment-timezone: 0.5.34
  • moment: 2.29.3
  • TypeScript: 4.6.3
  • Node: 16.14.2

Issue description:

import 'moment-timezone';
import moment from 'moment';
moment.tz.setDefault('UTC');

Gives the following TypeScript compilation error:

Property 'tz' does not exist on type 'typeof moment' 

Downgrading to moment 2.9.2 fixes the issue, I don't have @types/moment-timezone installed.

Seems similar to #385

@aailyin
Copy link

aailyin commented Apr 27, 2022

The same issue with versions:

"moment": "^2.29.3",
"moment-timezone": "^0.5.34",
"typescript": "~4.5.5"

Downgraded to 2.29.1, but it contains vulnerabilities.

@AbdelrahmanHafez
Copy link
Author

AbdelrahmanHafez commented Apr 27, 2022

@aailyin
For what it's worth, you don't need @types/moment-timezone anymore, moment-timezone is shipped with its own types.

@aailyin
Copy link

aailyin commented Apr 27, 2022

@AbdelrahmanHafez Ah, you're right. Removed. Thanks!

@gilmoreorless
Copy link
Member

This is probably caused by having multiple versions of moment in your package dependencies somewhere. See #982 (comment) for a more detailed explanation.

@AbdelrahmanHafez
Copy link
Author

AbdelrahmanHafez commented May 6, 2022

I ended up removing import moment from 'moment' altogether in favor of import moment from 'moment-timezone'.
I also removed moment from package.json.

The expectation here is to have the same exact behavior, and moment.tz.setDefault('UTC'); will reflect on everywhere as it was before with moment. Correct? @gilmoreorless

@gilmoreorless
Copy link
Member

@AbdelrahmanHafez that sounds right to me.

@AbdelrahmanHafez
Copy link
Author

@gilmoreorless Thank you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants