Closed as not planned
Closed as not planned
Description
Type: Bug
In this code:
class Foo {
/** @param {number} bar */
constructor (bar) {
this.bar = bar;
}
}
const foo = new Foo(37);
console.log(foo.bar);
the type of property bar
is inferred from the parameter type via the constructor assignment, as verified by:
- VS Code showing
(property) Foo.bar: number
when I hover onfoo.bar
in the last line tsc --noImplicitAny
making no complaints
but VS Code shows (property) Foo.bar: any
when I hover on this.bar
in the constructor.
I think that's simply a bug — at least I can't think of a reason it ought to be that way, and it has misled me into spending time troubleshooting inference or explicitly declaring the type.
Seen originally in latest stable VS Code and now also in VS Code Insiders with no extensions.
VS Code version: Code - Insiders 1.97.0-insider (Universal) (3d0aeb47a2ecfde9ff5141470b30c36d41c321d9, 2025-01-20T05:04:25.114Z)
OS version: Darwin arm64 24.2.0
Modes:
System Info
Item | Value |
---|---|
CPUs | Apple M1 Pro (10 x 2400) |
GPU Status | 2d_canvas: enabled canvas_oop_rasterization: enabled_on 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 video_decode: enabled video_encode: enabled webgl: enabled webgl2: enabled webgpu: enabled webnn: disabled_off |
Load (avg) | 7, 6, 5 |
Memory (System) | 32.00GB (0.72GB free) |
Process Argv | |
Screen Reader | no |
VM | 0% |
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805:30301674
vsaa593cf:30376535
py29gd2263:31024238
c4g48928:30535728
2i9eh265:30646982
962ge761:30841072
pythonnoceb:30776497
dsvsc014:30777825
dsvsc015:30821418
pythonmypyd1:30859725
h48ei257:31000450
pythontbext0:30879054
cppperfnew:30980852
pythonait:30973460
dvdeprecation:31040973
dwnewjupyter:31046869
nativerepl1:31134653
pythonrstrctxt:31093868
nativeloc1:31118317
cf971741:31144450
e80f6927:31120813
iacca1:31150324
notype1:31143044
dwcopilot:31158714
h409b430:31177054
5b1c1929:31184661
6074i472:31201624
dwoutputs:31217127
6e63a538:31218797