TypeScript CFA(Control Flow Analysis)失败,在switch语句中的fallthrough子句中,

to94eoyn  于 9个月前  发布在  TypeScript
关注(0)|答案(1)|浏览(104)

TypeScript版本: master
搜索词:
代码:

  1. declare const o: { c?: 1; };
  2. switch (0) {
  3. case 0:
  4. break;
  5. case o.c && o.c.valueOf():
  6. case o.c && o.c.valueOf():
  7. break;
  8. }

预期行为:

通过

实际行为:

  1. $ node built/local/tsc.js index.ts --strictNullChecks
  2. index.ts:5:15 - error TS2532: Object is possibly 'undefined'.
  3. 5 case o.c && o.c.valueOf():
  4. ~~~

Playground链接:
相关问题:

pdsfdshx

pdsfdshx1#

同时使用 declare const c?: number; 并移除 o. 的所有位置。

相关问题