aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/utilities/language-untilities.ts
diff options
context:
space:
mode:
author杨宇千 <crupest@outlook.com>2019-03-11 21:30:22 +0800
committerGitHub <noreply@github.com>2019-03-11 21:30:22 +0800
commit988e07fce184b72c35020e4bde4079bdd305fb7c (patch)
tree9770d2ac8ce0b856928fcc83cf943b077e63f5c8 /Timeline/ClientApp/src/app/utilities/language-untilities.ts
parent6f02dc7094d1304501e7ffd6c39ecf89369202c7 (diff)
parent9a11e4f5081d6dff7f1587e636f39de4b8983753 (diff)
downloadtimeline-988e07fce184b72c35020e4bde4079bdd305fb7c.tar.gz
timeline-988e07fce184b72c35020e4bde4079bdd305fb7c.tar.bz2
timeline-988e07fce184b72c35020e4bde4079bdd305fb7c.zip
Merge pull request #12 from crupest/strict
Use strict check of typescript compiler.
Diffstat (limited to 'Timeline/ClientApp/src/app/utilities/language-untilities.ts')
-rw-r--r--Timeline/ClientApp/src/app/utilities/language-untilities.ts12
1 files changed, 12 insertions, 0 deletions
diff --git a/Timeline/ClientApp/src/app/utilities/language-untilities.ts b/Timeline/ClientApp/src/app/utilities/language-untilities.ts
new file mode 100644
index 00000000..be9df2dc
--- /dev/null
+++ b/Timeline/ClientApp/src/app/utilities/language-untilities.ts
@@ -0,0 +1,12 @@
+export function nullIfUndefined<T>(value: T | undefined): T | null {
+ return value === undefined ? null : value;
+}
+
+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;
+ }
+}