Browse Source

add assertUnreachable helper

- to type check if, e.g. if/switch statements are exhaustive
- TODO use...
Alexander Rose 4 years ago
parent
commit
d45d5c0e55
1 changed files with 6 additions and 2 deletions
  1. 6 2
      src/mol-util/type-helpers.ts

+ 6 - 2
src/mol-util/type-helpers.ts

@@ -1,5 +1,5 @@
 /**
- * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
+ * Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
  *
  * @author Alexander Rose <alexander.rose@weirdbyte.de>
  * @author David Sehnal <david.sehnal@gmail.com>
@@ -25,4 +25,8 @@ export type NonNullableArray<T extends any[] | ReadonlyArray<any>> = T extends a
 export function ObjectKeys<T extends object>(o: T) {
     return Object.keys(o) as (keyof T)[];
 }
-export interface FiniteArray<T, L extends number = number> extends ReadonlyArray<T> { length: L };
+export interface FiniteArray<T, L extends number = number> extends ReadonlyArray<T> { length: L };
+
+export function assertUnreachable(x: never): never {
+    throw new Error('unreachable');
+}