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: 
`typescript-eslint` has *"exhaustiveness checking in switch with union type"* rule:  

[@typescript-eslint/switch-exhaustiveness-check](https://github.com/typescript-eslint/typescript-eslint/blob/9e0f6ddef7cd29f355f398c90f1986e51c4854f7/packages/eslint-plugin/docs/rules/switch-exhaustiveness-check.md)

To configure this, enable the rule in `package.json` and enable the TypeScript parser. An example that works with React 17:

```json
"eslintConfig": {
    "rules": {
        "@typescript-eslint/switch-exhaustiveness-check": "warn"
    },
    "parser": "@typescript-eslint/parser",
    "parserOptions": {
        "project": "./tsconfig.json"
    }
},

```

[![enter image description here](https://i.stack.imgur.com/HQmVc.png)](https://i.stack.imgur.com/HQmVc.png)
You can use the mapped type for this:

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

type ColorMapper = {
  [Property in Color]: string
}

const colorMap: ColorMapper = {
  [Color.Red]: "red",
  [Color.Green]: "green",
  [Color.Blue]: "blue",
}

function getColorName(c: Color): string {
  return colorMap[c];
} 

```

After you add a new value to `Color` you will need to meet `ColorMapper` requirements.