You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
this within function typed as any when annotated with JSDoc #51868
When function is annotated with JSDoc then even if the type explicitly specifies the type of this, the this is typed as any within the function. It seems to work in a *.ts file but not in *.js with JSDoc annotation.
Also it seems to be a regression (or intentional change) in 4.9.4.
🔎 Search Terms
jsdoc this any
🕗 Version & Regression Information
This changed between versions 4.8.4 and 4.9.4
⏯ Playground Link
Stackblitz link is below but it doesn't reproduce there as it doesn't seem to support JSDoc well.
Note: The current version of VSCode might default to 4.8.4 version in which case the issue will not show up but it reproduces after switching to version of typescript from the project in the bottom right corner of the status bar.
This seems to be an issue specific to typing function declarations. If you switch to a variable declaration initialized to a function expression, it works:
/** @type {import('./types').Module} */exportconstSentryModule=function(){returnthis.test()// ^^^^ Property 'test' does not exist on type 'ModuleThis'.}
But on the other hand, it’s not as if the annotation on the function declaration does nothing. Mismatched parameters errors as expected:
/** @type {import('./types').Module} */// ^^^^^^^^^^^^^^^^^^^^^^^^ The type of a function declaration must match the function's signature.exportdefaultfunctionSentryModule(a,b){returnthis.test()}
Activity
rchl commentedon Dec 13, 2022
Note: The current version of VSCode might default to 4.8.4 version in which case the issue will not show up but it reproduces after switching to version of typescript from the project in the bottom right corner of the status bar.
andrewbranch commentedon Dec 19, 2022
This seems to be an issue specific to typing function declarations. If you switch to a variable declaration initialized to a function expression, it works:
But on the other hand, it’s not as if the annotation on the function declaration does nothing. Mismatched parameters errors as expected:
This inconsistency does seem like a bug.