Type: Bug
- Open Visual Studio Code with TypeScript enabled.
- Create a
.ts file and insert the following code:
class Reproducer {
n: number = 0;
constructor(public enabled: boolean) { }
increase() {
if (this.enabled) {
++this.n;
}
}
hello() {
if (this.n === 0) {
console.log("Hello");
this.increase();
if (this.n === 1) {
console.log(" world");
}
}
}
}
- Hover over or inspect the condition
if (this.n === 1) inside the hello() method.
- Observe the TypeScript diagnostic error:
"This comparison appears to be unintentional because the types '0' and '1' have no overlap. ts(2367)"
- Expected behavior:
- No error should be reported.
this.n may be mutated via this.increase() before the second comparison, so this.n === 1 is a valid and reachable condition.
- Actual behavior:
- TypeScript incorrectly infers
this.n as the literal type 0 within the entire if (this.n === 0) block, ignoring the mutation from this.increase().
- This results in a false-positive error indicating that
0 and 1 have no overlap.
- Additional notes:
- This appears to be a control flow analysis issue where TypeScript does not properly account for side effects of method calls that mutate class state.
- The issue may relate to overly aggressive narrowing of
this.n within the conditional scope.
VS Code version: Code 1.121.0 (f6cfa2ea2403534de03f069bdf160d06451ed282, 2026-05-19T11:51:53+02:00)
OS version: Windows_NT x64 10.0.19045
Modes: Restricted
System Info
| Item |
Value |
| CPUs |
12th Gen Intel(R) Core(TM) i5-12600KF (16 x 3686) |
| GPU Status |
2d_canvas: enabled GPU0: VENDOR= 0x10de, DEVICE=0x2803 [NVIDIA GeForce RTX 4060 Ti], DRIVER_VENDOR=NVIDIA, DRIVER_VERSION=32.0.15.6094 ACTIVE GPU1: VENDOR= 0x10de, DEVICE=0x2803 [NVIDIA GeForce RTX 4060 Ti], DRIVER_VERSION=32.0.15.6094 GPU2: VENDOR= 0x1414, DEVICE=0x008c [Microsoft Basic Render Driver], DRIVER_VERSION=10.0.19041.5794 Machine model name: Machine model version: direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_graphite: disabled_off trees_in_viz: disabled_off video_decode: enabled video_encode: enabled webgl: enabled webgl2: enabled webgpu: enabled webnn: disabled_off |
| Load (avg) |
undefined |
| Memory (System) |
63.84GB (51.89GB free) |
| Process Argv |
--crash-reporter-id 999d7587-7a41-4103-ac56-5e8d1d131ec7 |
| Screen Reader |
no |
| VM |
0% |
Extensions (1)
| Extension |
Author (truncated) |
Version |
| vscode-icons |
vsc |
12.18.0 |
(1 theme extensions excluded)
A/B Experiments
vsliv368cf:30146710
pythonvspyt551cf:31249601
binariesv615:30325510
nativeloc1:31344060
dwcopilot:31170013
dwoutputs:31242946
copilot_t_ci:31333650
e5gg6876:31282496
pythonrdcb7:31342333
6518g693:31463988
aj953862:31281341
6abeh943:31336334
envsdeactivate2:31505458
cloudbuttont:31379625
3efgi100_wstrepl:31403338
ec5jj548:31422691
cp_cls_c_966_ss:31454199
inlinechat_v2_hd992725:31505030
4je02754:31466945
8hhj4413:31478653
38bie571_auto:31426784
cp_cls_c_1081:31454833
conptydll_true:31498968
e9c30283:31461165
test_treatment2:31471001
46204921:31447328
idci7584:31464702
e3e4d672:31494082
ei9d7968:31496641
chat:31457767
7e187181:31503455
ghj88844:31499326
ddid_t:31478206
hmra_i5g22:31518061
getcmakediagnosticson:31489824
7df3h592:31512476
cp_cls_t_1082:31516087
logging_enabled_new:31498466
db5d2638:31499441
jb_cp_cls_c_632:31517842
b1ei0813:31506238
748c7209:31512887
cg448276_tst_on:31514358
32d76977:31512328
ha629193:31508444
539gd155_c:31506875
jh5f2457_c:31515489
61138546:31518536
Type: Bug
.tsfile and insert the following code:if (this.n === 1)inside thehello()method.this.nmay be mutated viathis.increase()before the second comparison, sothis.n === 1is a valid and reachable condition.this.nas the literal type0within the entireif (this.n === 0)block, ignoring the mutation fromthis.increase().0and1have no overlap.this.nwithin the conditional scope.VS Code version: Code 1.121.0 (f6cfa2ea2403534de03f069bdf160d06451ed282, 2026-05-19T11:51:53+02:00)
OS version: Windows_NT x64 10.0.19045
Modes: Restricted
System Info
GPU0: VENDOR= 0x10de, DEVICE=0x2803 [NVIDIA GeForce RTX 4060 Ti], DRIVER_VENDOR=NVIDIA, DRIVER_VERSION=32.0.15.6094 ACTIVE
GPU1: VENDOR= 0x10de, DEVICE=0x2803 [NVIDIA GeForce RTX 4060 Ti], DRIVER_VERSION=32.0.15.6094
GPU2: VENDOR= 0x1414, DEVICE=0x008c [Microsoft Basic Render Driver], DRIVER_VERSION=10.0.19041.5794
Machine model name:
Machine model version:
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
trees_in_viz: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Extensions (1)
(1 theme extensions excluded)
A/B Experiments