marnusw / date-fns-tz

Complementary library for date-fns v2 adding IANA time zone support
MIT License
1.01k stars 112 forks source link

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

Closed brettwillis closed 2 months ago

brettwillis commented 2 months ago

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.

https://github.com/marnusw/date-fns-tz/blob/4e2a2acd53f79775586f36e143f9ca438bbdadc8/typings.d.ts#L82-L170

marnusw commented 2 months ago

@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?

brettwillis commented 2 months ago

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

brettwillis commented 2 months ago

@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. 👍🏼

marnusw commented 2 months ago

Thanks for the feedback @brettwillis. 3.0.1 published.