-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationRelates to JSDoc parsing and type generation
Milestone
Description
Bug Report
π Search Terms
JSDoc access modifier
π Version & Regression Information
- This changed in version
v3.8probably because JSDoc accessibility modifiers were introduced; that is to say: it never worked
β― Playground Link
Playground Link: Provided
π» Code
/** @class */
function Legacy () {
/** @protected */
this.prop = 1; // should not be an error
this.doStuff(); // should not be an error
}
/** @private */
Legacy.prototype.doStuff = function () {
this.prop; // should not be an error
this.doStuff(); // should not be an error
}
class C {
/** @protected */
prop = 1;
}
/** @this {C} */
function fn() {
this.prop; // the equivalent works in TS
}Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"checkJs": true,
"allowJs": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": 2,
"target": "ES2017",
"jsx": "React",
"module": "ESNext"
}
}π Actual behavior
Using legacy class syntax and so-called "assignment declarations" don't recognize that the properties are actually accessed inside the class. That's because the checker logic only looks for real ClassLikeDeclaration Nodes.
Note that @readonly correctly recognizes function Legacy as the constructor and allows assignment there.
Using a protected member in a function with explicit this-parameter works in TS, but doesn't when using @this in JS.
π Expected behavior
No errors in the code.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationRelates to JSDoc parsing and type generation