diff options
author | crupest <crupest@outlook.com> | 2019-03-11 21:21:02 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-03-11 21:21:02 +0800 |
commit | 9a11e4f5081d6dff7f1587e636f39de4b8983753 (patch) | |
tree | 9770d2ac8ce0b856928fcc83cf943b077e63f5c8 /Timeline/ClientApp/src/app/utilities/language-untilities.ts | |
parent | 6e8434fa885bdb7ef9fd0f09a8cd29c0e17cef5b (diff) | |
download | timeline-9a11e4f5081d6dff7f1587e636f39de4b8983753.tar.gz timeline-9a11e4f5081d6dff7f1587e636f39de4b8983753.tar.bz2 timeline-9a11e4f5081d6dff7f1587e636f39de4b8983753.zip |
Fix some compile bugs.
Diffstat (limited to 'Timeline/ClientApp/src/app/utilities/language-untilities.ts')
-rw-r--r-- | Timeline/ClientApp/src/app/utilities/language-untilities.ts | 9 |
1 files changed, 6 insertions, 3 deletions
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<T>(value: T | undefined): T | null { return value === undefined ? null : value; } -export function throwIfFalsy(value: any, name: string = '<unknown name>') { - if (!value) { - throw new Error(name + ' is falsy.'); +export function throwIfNullOrUndefined<T>(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; } } |