Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

JSDoc support @private and @protected annotations within js files #22047

Closed
que-etc opened this issue Feb 20, 2018 · 4 comments
Closed

JSDoc support @private and @protected annotations within js files #22047

que-etc opened this issue Feb 20, 2018 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@que-etc
Copy link

que-etc commented Feb 20, 2018

TypeScript Version: 2.8.0-dev.20180217

Search Terms:

  • jsdoc private
  • jsdoc protected

Code

class MyClass {
    /**
     * @private
     */
    privateProperty = 'private';

    /**
     * @protected
     */
    protectedProperty = 'protected';
}

const instance = new MyClass();

instance.privateProperty = 'so-much-for-private';
instance.protectedProperty = 'so-much-for-protected';

Expected behavior:
Following errors should be thrown if --checkJs is enabled:

  • When accessing private property: Property 'privateProperty' is private and only accessible within class 'MyClass'.
  • When accessing protected property: Property 'protectedProperty' is protected and only accessible within class 'MyClass' and its subclasses.

Actual behavior:
@private and @protected annotations are being ignored.

@que-etc
Copy link
Author

que-etc commented Feb 20, 2018

It seems that PR #21455 provides support of the @private annotation.

@mhegazy
Copy link
Contributor

mhegazy commented Feb 21, 2018

Duplicate of #14009

@mhegazy mhegazy marked this as a duplicate of #14009 Feb 21, 2018
@mhegazy mhegazy added the Duplicate An existing issue was already created label Feb 21, 2018
@que-etc
Copy link
Author

que-etc commented Feb 21, 2018

@mhegazy looks like we got our wires crossed. Issue that you mentioned requires showing private/protected properties in a suggestions list, while this one suggests making former properties behave similar to those defined in .ts files:

class MyClass {
    private privateProp = 'private';
}

const instance = new MyClass();

// In TS files following error is shown:
// "Property 'privateProperty' is private and only accessible within class 'MyClass'"
instance.privateProp = 'new-value'; 

So, I'd expect that in .js files, an attempt to access properties marked with @private access modifier would raise the same error as in .ts files. Of course, only if --checkJs flag is enabled.

@que-etc
Copy link
Author

que-etc commented Feb 21, 2018

I've just re-read that issue. You are right. Sorry, I wish I had searched better before opening a new ticket.

@que-etc que-etc closed this as completed Feb 21, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants