-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
SuggestionAn idea for TypeScriptAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it addsAn issue which adding support for may be too complex for the value it adds
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)
Metadata
Metadata
Assignees
Labels
SuggestionAn idea for TypeScriptAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it addsAn issue which adding support for may be too complex for the value it adds