@sinchsmb/ui-kit
Version:
UI kit for SinchSMB frontend
42 lines (41 loc) • 1.02 kB
TypeScript
/**
* A utility for checking that all values from enum have been processed into the switch case.
*
* For example you have enum:
* ```
* enum TestEnum {
* One,
* Two,
* Three
* }
* ```
*
* And want process all values from enum. You write something like this:
* ```
* const value: TestEnum = ...;
*
* switch (value) {
* case TestEnum.One: ...; break;
* case TestEnum.Two: ...; break;
* case TestEnum.Three: ...; break;
* }
* ```
*
* But you want protect this code from case when you add new value to enum and forgot process it in
* switch-case. For this you can write:
* ```
* const value: TestEnum = ...;
*
* switch (value) {
* case TestEnum.One: ...; break;
* case TestEnum.Two: ...; break;
* case TestEnum.Three: ...; break;
* default: assertUnreachable(value);
* }
* ```
*
* And if you add `TestEnum.Four`, then you get TS error in `default`.
*
* @see https://stackoverflow.com/a/39419171/1778685
*/
export declare function assertUnreachable(value: never): never;