moment / luxon

⏱ A library for working with dates and times in JS
https://moment.github.io/luxon
MIT License
15.12k stars 728 forks source link

Types are not the same as in the documentation #1504

Closed dimitarbikov closed 10 months ago

dimitarbikov commented 10 months ago

Describe the bug With the 3.2.2 types update, some properties can now return null, which breaks everything. The .toISO() function should return string, but since @types/luxon@3.2.2 it was extended to return string | null.

To Reproduce image

Looking at the documentation, the return type should be string: https://moment.github.io/luxon/api-docs/index.html#datetimetoiso:~:text=Returns%20an%20ISO%208601%2Dcompliant%20string%20representation%20of%20this%20DateTime

Same with zone name: https://moment.github.io/luxon/api-docs/index.html#zonename It says it should return a string, but the actual type is string or null: image

Actual vs Expected behavior I wouldn't expect calling ToISO() on a new DateTime object to return null. Desktop (please complete the following information):

JoshStrobl commented 10 months ago

Was just about to report this as well. Updated to latest luxon and have this regression as well. Both were previously valid types (strings).

dasa commented 10 months ago

This is related to #1474

JoshStrobl commented 10 months ago

I don't really understand how this was changed and not updated to a new major Semver. This completely breaks builds. Either you are now having to deal with putting try / catches everywhere (or use a library which exposes a try func for you instead) or all the typing errors that were otherwise valid before. The behavior of the respective output functions like toISO fundamentally changed to be API breaking. If you were to do the suggestion of setting to throw on invalid, behavior where it was acceptable to provide invalid values but check through the existing isValid property now completely break and behavior otherwise breaks valid type usage.

Why even bother to do versioning if not going to actually follow proper versioning?

diesieben07 commented 10 months ago

@types/luxon is not maintained by the Luxon maintainers. This is the wrong repository for this issue as far as I understand.