marnusw/date-fns-tz

`typings.d.ts` no longer accurate for named exports in V3

brettwillis opened this issue · 4 comments

As of V3

All functions are now exported using named exports

The typings still describe export = ... exports, so it is now impossible to write code that is type-correct and works at runtime.

date-fns-tz/typings.d.ts

Lines 82 to 170 in 4e2a2ac

declare module 'date-fns-tz/format' {
import { format } from 'date-fns-tz'
export = format
}
declare module 'date-fns-tz/formatInTimeZone' {
import { formatInTimeZone } from 'date-fns-tz'
export = formatInTimeZone
}
declare module 'date-fns-tz/fromZonedTime' {
import { fromZonedTime } from 'date-fns-tz'
export = fromZonedTime
}
declare module 'date-fns-tz/getTimezoneOffset' {
import { getTimezoneOffset } from 'date-fns-tz'
export = getTimezoneOffset
}
declare module 'date-fns-tz/toDate' {
import { toDate } from 'date-fns-tz'
export = toDate
}
declare module 'date-fns-tz/toZonedTime' {
import { toZonedTime } from 'date-fns-tz'
export = toZonedTime
}
declare module 'date-fns-tz/format/index' {
import { format } from 'date-fns-tz'
export = format
}
declare module 'date-fns-tz/formatInTimeZone/index' {
import { formatInTimeZone } from 'date-fns-tz'
export = formatInTimeZone
}
declare module 'date-fns-tz/fromZonedTime/index' {
import { fromZonedTime } from 'date-fns-tz'
export = fromZonedTime
}
declare module 'date-fns-tz/getTimezoneOffset/index' {
import { getTimezoneOffset } from 'date-fns-tz'
export = getTimezoneOffset
}
declare module 'date-fns-tz/toDate/index' {
import { toDate } from 'date-fns-tz'
export = toDate
}
declare module 'date-fns-tz/toZonedTime/index' {
import { toZonedTime } from 'date-fns-tz'
export = toZonedTime
}
declare module 'date-fns-tz/format/index.js' {
import { format } from 'date-fns-tz'
export = format
}
declare module 'date-fns-tz/formatInTimeZone/index.js' {
import { formatInTimeZone } from 'date-fns-tz'
export = formatInTimeZone
}
declare module 'date-fns-tz/fromZonedTime/index.js' {
import { fromZonedTime } from 'date-fns-tz'
export = fromZonedTime
}
declare module 'date-fns-tz/getTimezoneOffset/index.js' {
import { getTimezoneOffset } from 'date-fns-tz'
export = getTimezoneOffset
}
declare module 'date-fns-tz/toDate/index.js' {
import { toDate } from 'date-fns-tz'
export = toDate
}
declare module 'date-fns-tz/toZonedTime/index.js' {
import { toZonedTime } from 'date-fns-tz'
export = toZonedTime
}

@brettwillis I had to update the build scripts to maintain your changes. I think the individual type files next to the functions had to be changed too. (The lib really needs to be rewritten in TS properly.)

I thought it best to release 3.0.1-beta.0 first. Will you let me know if types work properly for you using this release?

@marnusw yes just tested the typings in 3.0.1-beta.0 work great. Thanks for the quick turn-around!

@marnusw actually there is a curious behaviour where if all imports in a file use ESM date-fns-tz/esm/... then VS Code suddenly says Cannot find module 'date-fns-tz/esm/...' or its corresponding type declarations.ts(2307) for all of them, but as soon as any import in the file refers to the root/non-ESM date-fns-tz/... then VS Code is satisfied with all the imports.

Checked again and 3.0.0 has the same issue.

Not too sure what the root cause is there but maybe it can be resolved if rewritten in TS properly.

However at least 3.0.1-beta.0 has accurate typings. 👍🏼

Thanks for the feedback @brettwillis. 3.0.1 published.