moment / luxon

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

InvalidDateTimeError should not be private / should be an exported type #1430

Open Zajozor opened 1 year ago

Zajozor commented 1 year ago

Describe the bug InvalidDateTimeError is currently private, or more specifically not exported in the @types/luxon. https://github.com/moment/luxon/blob/07023283e74321c2080de9bb73070a3ffd2a7acc/src/errors.js#L11

This change - https://github.com/DefinitelyTyped/DefinitelyTyped/pull/64995 made us want to adopt luxon's strict mode where you set Settings.throwOnInvalid = true

To Reproduce

This would enable a use case like this:

try {
  DateTime.now().setZone(timeZone) // Throws if invalid
} catch (e: unknown) {
  if (e instanceof InvalidDateTimeError){ <--- But there is no place from which we could import `InvalidDateTimeError` 
    // thrown because of invalid timezone
  }
  throw e // otherwise propagate
}

Actual vs Expected behavior Currently we can't tell if an error is InvalidDateTimeError other than some message matching.

Desktop (please complete the following information):

Additional context Please do let me know if there is some other nice way of distinguishing this error from other errors :) Maybe I'm just missing something!

ps. ty for the great library!