Typescript: Provide editor feature for filling in 'switch' cases for common scenario

Created on 30 Nov 2019  路  5Comments  路  Source: microsoft/TypeScript

Hi,

Not a bug, but a feature request please. Have been asked to post feature request here.

Version Used:
N/A

Steps to Reproduce:

  1. Create an enum.
  2. Create a variable in a method for that enum, assign value.
  3. Type sw(tab)(tab) and press Enter.

Expected Behavior:
Like C#, enum values to be auto-listed as cases.

 let status: StatusETW = etw.EtwStatusId as StatusETW;
            switch (status) {
                case StatusETW.Cancelled:
                    break;
                case StatusETW.Completed:
                    break;
                case StatusETW.Draft:
                    break;
                case StatusETW.EligibleToWork:
                    break;
                case StatusETW.Expired:
                    break;
                case StatusETW.UnComplete:
                    break;
                case StatusETW.Unlock:
                    break;
                default:
                    break;
            }

Actual Behavior:
This happens:

let status: StatusETW = etw.EtwStatusId as StatusETW;
            switch (status) {

                default:
            }

Kind Regards.

Awaiting More Feedback Suggestion

Most helpful comment

All 5 comments

That would be very nice to have in VSCode, too!

vs implment this uses snippet. https://docs.microsoft.com/en-us/visualstudio/ide/code-snippet-functions?view=vs-2019
But I think this should be a codeaction in typescript.

switch(expr)
{
default:
}

When cursor at switch or expr , and if expr's type is an enum type and empty switch body, should enable the code action to generate all enum cases.
Here enum means real enum type or union type like 'A'|'B'|1|true|null.

@TypeScript team, pretty please :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yortus picture yortus  路  157Comments

xealot picture xealot  路  150Comments

metaweta picture metaweta  路  140Comments

kimamula picture kimamula  路  147Comments

fdecampredon picture fdecampredon  路  358Comments