如何从枚举类型创建一个开关语句,因此它会自动填充每个枚举成员的情况?

发布于 2025-02-11 06:08:14 字数 408 浏览 5 评论 0原文

此功能存在于Visual Studio Professional中,但不知道如何在VS代码中进行操作。

例如,我有颜色枚举这样的枚举:

enum Colors {
    Red,
    Blue,

因此,当我编写这样的开关语句时:

function getColor(colors: Colors) {
 switch (colors) 
}

编辑器自动为我填充所有情况,例如:

switch (colors) {
    case Colors.Red:      
      break;
    case Colors.Blue:      
      break;
}

This feature exists in Visual Studio Professional, but no idea how to do it in VS Code.

For example I have Colors enum like this:

enum Colors {
    Red,
    Blue,

So when I write a switch statement like this:

function getColor(colors: Colors) {
 switch (colors) 
}

The editor to automatically fill every case for me, like:

switch (colors) {
    case Colors.Red:      
      break;
    case Colors.Blue:      
      break;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹雨成花 2025-02-18 06:08:14

有扩展名称称为hocus pocus:

​>选项

There is extension that covers this case called Hocus Pocus:

https://marketplace.visualstudio.com/items?itemName=nicoespeon.hocus-pocus

When installed just hover over switch statement and open quick fix menu (ctrl + . or cmd + .) and You should see Create all cases option

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文