-
Notifications
You must be signed in to change notification settings - Fork 116
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 compile error: Duplicate identifier 'Options' #3
Comments
This is being fixed in https://github.com/marnusw/date-fns-tz/commits/fixTypescript, but it is not ready yet. Tried Also tried cloning this repo, switching to the fixTypescript branch and running the following:
... but encountered multiple issues during build and packaging and compiling, so I assume the branch reflects work in progress. |
Thanks for the detailed bug report. Yes, work in progress, just a little slow over the holiday period. I'll keep you posted. |
I have published import utcToZonedTime from 'date-fns-tz/utcToZonedTime' works correctly now, but the named import import { zonedTimeToUtc } from 'date-fns-tz' errors with |
Thanks for the update @marnusw! I looked at the issue you're talking about, and found an explanation and a potential fix here. I tried changing the Unfortunately I'm not well-versed in creating declarations files either, so I'm not sure if there's a better way to fix it. It seems like this could get clunky if you needed a type from date-fns in multiple places throughout the declaration file... |
Thank you @klanchman! It looks like all Typescript issues have been resolved in |
Checked it out in my full project and seems good. Thank you! 😄 |
@klanchman It appears this edit: Here's an example typings file that works fine in TS 2.8 and 3.2: declare module 'date-fns-tz' {
import { Locale } from "date-fns"
export type OptionsWithTZ = {
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
additionalDigits?: 0 | 1 | 2
timeZone?: string
locale?: Locale
includeSeconds?: boolean
addSuffix?: boolean
unit?: 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year'
roundingMethod?: 'floor' | 'ceil' | 'round'
awareOfUnicodeTokens?: boolean
}
export function toDate(
argument: Date | string | number,
options?: OptionsWithTZ
): Date
export function utcToZonedTime(
date: Date | string | number,
timeZone: string,
options?: OptionsWithTZ
): Date
export function zonedTimeToUtc(
date: Date | string | number,
timeZone: string,
options?: OptionsWithTZ
): Date
}
declare module 'date-fns-tz/toDate' {
import { toDate } from 'date-fns-tz'
export default toDate
}
declare module 'date-fns-tz/zonedTimeToUtc' {
import { zonedTimeToUtc } from 'date-fns-tz'
export default zonedTimeToUtc
}
declare module 'date-fns-tz/utcToZonedTime' {
import { utcToZonedTime } from 'date-fns-tz'
export default utcToZonedTime
} |
Ah, I didn't notice that. I'm also using the create-react-app-typescript fork, but with TS 3.1. Your example deviates quite a bit from how the definition file is set up currently. It also doesn't account for the That said, it might not be a problem to take your example and just duplicate the |
This should be simple enough to change. I'll take a look when I can. Thank you for investigating. |
@kamranayub when I change the typings file to declare module 'date-fns-tz' {
import { Locale } from "date-fns"
export type OptionsWithTZ = {
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6
firstWeekContainsDate?: 1 | 2 | 3 | 4 | 5 | 6 | 7
additionalDigits?: 0 | 1 | 2
timeZone?: string
locale?: Locale
includeSeconds?: boolean
addSuffix?: boolean
unit?: 'second' | 'minute' | 'hour' | 'day' | 'month' | 'year'
roundingMethod?: 'floor' | 'ceil' | 'round'
awareOfUnicodeTokens?: boolean
}
} Then the other module declarations lower down break because But what about the final section that defines |
I have implemented @kamranayub 's suggestion in |
Looks to be working for me with TypeScript 3.1 and 3.3 🙂 |
Released in |
Seeing an issuee when trying to use
date-fns-tz
in a TypeScript project.Reproduction
create-react-app <projectName> --typescript
App.tsx
and importdate-fns
anddate-fns-tz
, e.g:npm start
/yarn start
Expected
App runs
Actual
Compile error
If I manually remove
Options
,OptionsAliased
,Locale
,LocaleAliased
fromnode_modules/date-fns-tz/typings.d.ts
, then it compiles, and I think the functions fromdate-fns-tz
are still typed as expected?The text was updated successfully, but these errors were encountered: