Skip to content

noUnusedLocals throws errors for "never" type. #31129

@technoligest

Description

@technoligest

Search Terms:
nounusedlocals never
nounusedlocals
never
never variable is not used error

Code

//NOTE: nounusedlocals is set to true in tsconfig.
enum Color {
  A,
  B,
}
function f(color: Color) {
  switch(color) {
    case Color.A:
      console.log("White");
      break;
    case Color.B:
      console.log("Black");
      break;
    default:
      const _:never = color;
  }
}

Expected behavior:
Compiles fine, prints nothing

Actual behavior:
Given variable _ is unused. _ is of type never which means it is expected to be never used. It is being declared as a compile time safety to ensure that we have cases over all the Color enum values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions