-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already createdSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
It is incredibly easy to make a copy/paste error for case clauses in a switch statement.
switch (node.kind) {
// ...
case SyntaxKind.TupleType:
// Do something with tuple types.
case SyntaxKind.TupleType:
// Do something with union types.
// ...
}While it is easily arguable that non-exhaustive cases can be allowed in TypeScript, there is no reason not to report duplicated cases.
"Obvious" semantics for case clauses in a single switch statement are as follows:
- Report when named entities with identical symbols are handled.
- Report when equal string literals are handled.
- Report when equal numeric literals (even 0.0 and 0) are handled.
- Report when
nullis handled more than once. - Report when
undefinedis handled more than once.
One interesting question is whether exhaustive cases for an enum should report an error when there is a default clause.
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already createdSuggestionAn idea for TypeScriptAn idea for TypeScript