如何从枚举类型创建一个开关语句,因此它会自动填充每个枚举成员的情况?
此功能存在于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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有扩展名称称为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