From 84eb1c67d64f6fa81fa0f695b7f88fe191541d71 Mon Sep 17 00:00:00 2001 From: Carson Full Date: Mon, 3 Apr 2023 16:11:51 -0500 Subject: [PATCH] Note the new TS option for throwOnInvalid. --- docs/validity.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/validity.md b/docs/validity.md index 7ad24685f..b09417f26 100644 --- a/docs/validity.md +++ b/docs/validity.md @@ -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.