Closed
Description
TypeScript Version: 2.3.4
Code
type Choices = {
type: "A"
};
function chooser(action: Choices): boolean {
switch (action.type) {
case "A":
return true;
default:
const exhaustivenessCheck: never = action;
return false;
}
}
Expected behavior:
Code compiles.
Actual behavior:
Receive Error:
test.ts(10,13): error TS2322: Type 'Choices' is not assignable to type 'never'.
Reasoning
For libraries like Redux, there are places where it makes sense to have a switch statement with a single case for Discriminated Unions. (e.g. in reducers with a single action)