【发布时间】:2021-09-15 11:06:49
【问题描述】:
- 我在 tsconfig.json 文件中启用了
noFallthroughCasesInSwitch选项。 - 该选项警告我一个“错误”,我想让 Typescript 编译器知道这是故意的。
- 没有记录,在线示例对我不起作用 - 我如何将其标记为故意?
function getRandomInt(max: number) {
return Math.floor(Math.random() * max);
}
switch(getRandomInt(3)) {
/* falls through */
/* fall through */
/* FALLTHROUGH */
case 1: /* falls through */ /* fall through */ /* FALLTHROUGH */ /* <----- Still getting an error here "Fallthrough case in switch. (7029)" */
/* falls through */
/* fall through */
/* FALLTHROUGH */
console.log(1);
/* falls through */
/* fall through */
/* FALLTHROUGH */
case 2:
console.log(2);
break;
}
也可以在此链接中看到错误:link。
但是TS Playground中有bug,所以你必须手动点击“TS Config”菜单,然后勾选noFallthroughCasesInSwitch选项,它会被打开,否则你不会看到错误。
【问题讨论】:
标签: typescript switch-statement