From 9a11e4f5081d6dff7f1587e636f39de4b8983753 Mon Sep 17 00:00:00 2001 From: crupest Date: Mon, 11 Mar 2019 21:21:02 +0800 Subject: Fix some compile bugs. --- Timeline/ClientApp/src/app/utilities/language-untilities.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'Timeline/ClientApp/src/app/utilities') diff --git a/Timeline/ClientApp/src/app/utilities/language-untilities.ts b/Timeline/ClientApp/src/app/utilities/language-untilities.ts index f898039a..be9df2dc 100644 --- a/Timeline/ClientApp/src/app/utilities/language-untilities.ts +++ b/Timeline/ClientApp/src/app/utilities/language-untilities.ts @@ -2,8 +2,11 @@ export function nullIfUndefined(value: T | undefined): T | null { return value === undefined ? null : value; } -export function throwIfFalsy(value: any, name: string = '') { - if (!value) { - throw new Error(name + ' is falsy.'); +export function throwIfNullOrUndefined(value: T | null | undefined, + lazyMessage: () => string = () => 'Value mustn\'t be falsy'): T | never { + if (value === null || value === undefined) { + throw new Error(lazyMessage()); + } else { + return value; } } -- cgit v1.2.3