Closed kjirou closed 4 years ago
This library is an extension of date-fns@2.0.0-alpha
and has date-fns
specified as a peer dependency. The date-fns
library contains the different locales and exports the Locale
type definition. Please import it from there when necessary.
I'm running into this as well when trying to upgrade from 0.1.1 to 1.0.7. I'm confused by your comment, @marnusw. The OP was not importing Locale
, just format
and dateFormat
from date-fns-tz
. This seems like an issue with the peer dependency range specified in date-fns-tz for date-fns, which is currently >=2.0.0-alpha.13
. I'm using date-fns@2.0.0-alpha.37
. Seems date-fns-tz is not actually compatible with the type definitions in that version of date-fns.
The intention is not that date-fns-tz
should re-export Locale
. The types should match up so it can work together seamlessly with date-fns
though. I, unfortunately, don't use this library in a statically typed project at the moment so I don't have full visibility of the current typings. I don't think much would have changed in the recent date-fns
versions but it is possibly something fell out of sync.
Looking at the OP's question again I still can't tell that it is necessarily a problem with date-fns-tz. If you could provide some more info on exactly what isn't working for you and how you think this lib might be at fault I could investigate it. I'll reopen this issue in the meantime.
date-fns-tz
imports the type Locale
from date-fns
here: https://github.com/marnusw/date-fns-tz/blob/master/src/index.js.flow#L4
As far as I can tell looking at date-fns
that type is not exported. So, when I run flow in a project depending on date-fns-tz, I get the following error:
Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/date-fns-tz/index.js.flow:4:15
Cannot import Locale because there is no Locale export in date-fns.
1│ // @flow
2│ // This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
3│
4│ import type { Locale } from 'date-fns'
5│
6│ type OptionsWithTZ = {
7│ weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,
That error is coming from within date-fns-tz
when flow evaluates its types.
I thought it was perhaps an issue with the version of date-fns
but that appears not to be the case because even the earliest version allowed by the peerDependency range does not have Locale
as an exported type.
Hopefully that helps. I tried my hand at updating with a PR myself, but when I found that Locale
was not exported at all from date-fns, I figured it would probably take some higher level decision-making about where that type should be defined. Perhaps a pull request against date-fns to export that type might be in order.
Thank you @chasingmaxwell for the thorough clarification. I will investigate further.
@marnusw We are getting the same issue as @chasingmaxwell
The type needs to changes to
import type { Locale } from 'date-fns/locale'
Then everything will work
cc @kangax
This same issue exists for all flow types for this project (as the flow types for date-fns 2.x use date-fnx/<thing>
and not a general flow type for the index.
The Interval
type is also not being exported from date-fns
. It's not a type that date-fns-tz
requires, but it would be useful to use the type defined by date-fns
in client code rather than redefining the type ourselves.
Thank you @maniator for the proposed fix. I have changed this in 1.0.8-beta.1
. Please confirm whether this fixes the issue with Flow and I'll publish a proper release.
@saiichihashimoto I am not a maintainer of date-fns
. If you would like additional types exposed please file an issue on the date-fns
project.
Thank you @maniator for the proposed fix. I have changed this in
1.0.8-beta.1
. Please confirm whether this fixes the issue with Flow and I'll publish a proper release.@saiichihashimoto I am not a maintainer of
date-fns
. If you would like additional types exposed please file an issue on thedate-fns
project.
Hmmm We no longer have that original issue, but now it just says
Cannot resolve module date-fns-tz.
when we run flow @marnusw
I have no idea why this is happening and won't be able to investigate this myself since I have never used Flow. I will happily try out any further suggestions, though. I'm guessing editing the installed files in node_modules
until the Flow types are fixed could be a way to go, then post the solution here and I'll update the source (or, even better, submit a PR).
With Typescript there was a problem with importing the Locale
type globally which then changed the type definition from global to module scope. Maybe that is the issue here as well. It could explain why the date-fns-tz
module is not resolved at all. With Typescript the solution was importing inside the module declaration block rather than at the top of the file, but I'm not sure what the equivalent would be for Flow.
I compiled the following code...
src/index.ts)
The following error occurred.
Environments
package-lock.json)
tsconfigs.json)