Skip to content

Issues with JSDoc private and protectedΒ #42237

@ajafff

Description

@ajafff

Bug Report

πŸ”Ž Search Terms

JSDoc access modifier

πŸ•— Version & Regression Information

  • This changed in version v3.8 probably 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generation

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions