Like others (#1421) I was caught off-guard by the typings update that declared many return values to be nullable. I had read the validity docs when I first encountered the library, but have forgotten them since (albeit using isValid in a few places) and not thought about what this meant for formatting methods like .toString() or .toISO().
The behaviour of returning null on invalid DateTime objects is completely missing from the API documentation afaics.
The TypeScript typings should not be the only reminder about this. I would expect the return type of all the to… methods to include | null in the API docs, a sentence like "If invalid, returns null." added to each of their descriptions, and also a section (warning) about this behaviour on the formatting docs.
Like others (#1421) I was caught off-guard by the typings update that declared many return values to be nullable. I had read the validity docs when I first encountered the library, but have forgotten them since (albeit using
isValid
in a few places) and not thought about what this meant for formatting methods like.toString()
or.toISO()
.The behaviour of returning
null
on invalidDateTime
objects is completely missing from the API documentation afaics.The TypeScript typings should not be the only reminder about this. I would expect the return type of all the
to…
methods to include| null
in the API docs, a sentence like "If invalid, returnsnull
." added to each of their descriptions, and also a section (warning) about this behaviour on the formatting docs.