aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/utilities/language-untilities.ts
blob: be9df2dce3f765254742c06af661aa85fd39a4a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
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;
  }
}