How do I check that a switch block is exhaustive in TypeScript?

前端 未结 10 977
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 10:57

I have some code:

enum Color {
    Red,
    Green,
    Blue
}

function getColorName(c: Color): string {
    switch(c) {
        case Color.Red:
                     


        
10条回答
  •  无人及你
    2020-12-02 11:38

    typescript-eslint has "exhaustiveness checking in switch with union type" rule:
    @typescript-eslint/switch-exhaustiveness-check

提交回复
热议问题