Question: I have some code:

```
enum Color {
    Red,
    Green,
    Blue
}

function getColorName(c: Color): string {
    switch(c) {
        case Color.Red:
            return 'red';
        case Color.Green:
            return 'green';
        // Forgot about Blue
    }

    throw new Error('Did not expect to be here');
}

```

I forgot to handle the `Color.Blue` case and I'd prefer to have gotten a compile error. How can I structure my code such that TypeScript flags this as an error?

Answer: 
As a nice twist on Ryan's answer, you can replace `never` with an arbitrary string to make the error message more user friendly.

```
function assertUnreachable(x: 'error: Did you forget to handle this type?'): never {
    throw new Error("Didn't expect to get here");
}

```

Now, you get:

```
return assertUnreachable(c);
       ~~~~~~~~~~~~~~~~~~~~~
       Type "Color.Blue" is not assignable to type "error: Did you forget to handle this type?"

```

This works because `never` can be assigned to anything, including an arbitrary string.
Create a custom function instead of using a `switch` statement.

```
export function exhaustSwitch<T extends string, TRet>(
  value: T,
  map: { [x in T]: () => TRet }
): TRet {
  return map[value]();
}

```

Example usage

```
type MyEnum = 'a' | 'b' | 'c';

const v = 'a' as MyEnum;

exhaustSwitch(v, {
  a: () => 1,
  b: () => 1,
  c: () => 1,
});

```

If you later add `d` to `MyEnum`, you will receive an error `Property 'd' is missing in type ...`