microsoft / microsoft/TypeScript
multiple cases with the same value are allowed in switch/case
Open
Nobody has claimed this yet.
Awaiting More Feedback
Suggestion
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
🔎 Search Terms
switch / case
same values on multiple cases
🕗 Version & Regression Information
4.9.4
💻 Code
// we are allowed to use same value on multiple cases.
// only the first one is executed
function test( value: string ) {
switch( value ) {
case 'a': {
console.log( "case 1");
break;
}
case 'b': {
console.log( "case 2");
break;
}
// should not be allowed
case 'a': {
console.log( "case 3");
break;
}
}
}
test( 'a' )
🙁 Actual behavior
the first case is executed
🙂 Expected behavior
an error should be emit to prevent such error
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the TypeScript Playground example in the issue and trace how the compiler checks duplicate switch case values. The work is done when repeated case values produce an error while valid switch cases continue compiling and executing as before; add or update coverage in the relevant compiler tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100