-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Domain: Completion ListsThe issue relates to showing completion lists in an editorThe issue relates to showing completion lists in an editorDomain: Quick FixesEditor-provided fixes, often called code actions.Editor-provided fixes, often called code actions.Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
Description
Suggestion
declare const example: "one" | "two" | "three"
switch(example) {
cas|
}
Offer in suggestions: 'case (add missing cases)'. Which would turn into:
declare const example: "one" | "two" | "three"
switch(example) {
case: "one":
// ...
break
case: "two":
// ...
break
case: "three":
// ...
break
}
Extra credit: add two options 'add missing cases' and 'add exhaustive missing cases' which adds a never in the default:
declare const example: "one" | "two" | "three"
switch(example) {
case: "one":
// ...
break
case: "two":
// ...
break
case: "three":
// ...
break
default: {
const exhaustiveCheck: never = value;
throw new Error(exhaustiveCheck);
}
}
declare const example: "one" | "two" | "three"
switch(example) {
case: "one": console.log("one") break;
cas|
}
Offer in suggestions:
- 'case (fill in missing cases)'
🔍 Search Terms
switch autocomplete switch suggestions switch fill case string union
✅ Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
📃 Motivating Example
I got me a long string literal enum, and I've got to cover all those cases.
💻 Use Cases
^
fatcerberus, DanielRosenwasser, Thundercraft5 and lensbarta-tarasyuk, uhyo, DanielRosenwasser, agentcooper, Thundercraft5 and 1 more
Metadata
Metadata
Assignees
Labels
Domain: Completion ListsThe issue relates to showing completion lists in an editorThe issue relates to showing completion lists in an editorDomain: Quick FixesEditor-provided fixes, often called code actions.Editor-provided fixes, often called code actions.Experience EnhancementNoncontroversial enhancementsNoncontroversial enhancementsSuggestionAn idea for TypeScriptAn idea for TypeScript