You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The TS type definitions state that the moment() function accepts null as the input, which it does, but it produces a monent instance with an "Invalid date".
The TS type definitions also state that Moment.toJSON() returns string, but if the date is invalid, it will return null.
TS types must be trusted, that's kind of the point. I had correctly typed data (my input was typed string | undefined | null), and called moment(input).toJSON(), expecting to get a string back, but got null, which made my application crash.
Desktop (please complete the following information):
OS: Mac, Node.JS 18.x
Please run the following code in your environment and include the output:
> console.log((new Date()).toString())
Thu Jan 11 2024 12:12:12 GMT+0100 (Central European Standard Time)
undefined
> console.log((new Date()).toLocaleString())
1/11/2024, 12:12:12 PM
undefined
> console.log((new Date()).getTimezoneOffset())
-60
undefined
> console.log(navigator.userAgent)
Uncaught ReferenceError: navigator is not defined
> console.log(moment.version)
2.29.4
Additional context
The text was updated successfully, but these errors were encountered:
utf26
added a commit
to utf26/moment
that referenced
this issue
Mar 21, 2024
Describe the bug
A clear and concise description of what the bug is.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The TS type definitions state that the
moment()
function acceptsnull
as the input, which it does, but it produces amonent
instance with an "Invalid date".The TS type definitions also state that
Moment.toJSON()
returnsstring
, but if the date is invalid, it will returnnull
.TS types must be trusted, that's kind of the point. I had correctly typed data (my input was typed
string | undefined | null
), and calledmoment(input).toJSON()
, expecting to get a string back, but gotnull
, which made my application crash.Desktop (please complete the following information):
Please run the following code in your environment and include the output:
Additional context
The text was updated successfully, but these errors were encountered: