Skip to content

Commit

Permalink
Note the new TS option for throwOnInvalid.
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonF committed Apr 3, 2023
1 parent 0702328 commit 84eb1c6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/validity.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ DateTime.now().setZone("America/Blorp"); //=> Error: Invalid DateTime: unsupport

You can of course leave this on in production too, but be sure to try/catch it appropriately.

For TypeScript users, this runtime setting narrows the return types. You need manually inform TypeScript of this setting with this snippet.
```ts
declare module 'luxon' {
interface TSSettings {
throwOnInvalid: true;
}
}
```
This will remove the null, etc. return types from getters/methods that would only do so for invalid objects.

## Invalid Durations

Durations can be invalid too. The easiest way to get one is to diff an invalid DateTime.
Expand Down

0 comments on commit 84eb1c6

Please sign in to comment.