Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Accept @property jsdoc #157792

Closed
barsdeveloper opened this issue Aug 10, 2022 · 1 comment
Closed

Accept @property jsdoc #157792

barsdeveloper opened this issue Aug 10, 2022 · 1 comment
Assignees
Labels
javascript JavaScript support issues upstream Issue identified as 'upstream' component related (exists outside of VS Code)

Comments

@barsdeveloper
Copy link

barsdeveloper commented Aug 10, 2022

Sometimes it is necessary to document classes with properties added dynamically (outside the class). The way I was documenting those before was the following way:

// @ts-check
 class ClassName {
    constructor () {
        /** @type {String} */
        this.propName
    }
}

But a recent update of VS Code made this illegal (Property 'propName' is used before being assigned.ts(2565))
There might be a way to document it using @property from JSDoc

// @ts-check
/**
 * Class definition
 * @property {String} propName
 */
 class ClassName {
    constructor () {
    }
}

But unfortunately it seems to be unsupported by VSCode.

EDIT:
I am aware there is the following syntax

 class ClassName {
    /** @type {String} */
    propName
    constructor () {
    }
}

This is not a satisfactory solution though because it will change the semantic of the code when you want to iterate over the properties of an object when its properties are defined in the super class (It changes the order of declaration)

@mjbvz
Copy link
Collaborator

mjbvz commented Aug 10, 2022

Tracked upstream becausehttps://github.com/microsoft/TypeScript/issues/28730

You're seeing that error because this.propName is just referencing the value without assigning it. You can initialize the value to fix it (and this would be preferable to @property IMO as the @property example would mean the types are inaccurate until the external assignment takes place):

class ClassName {
    constructor () {
        this.propName = '';
    }
}

@mjbvz mjbvz closed this as completed Aug 10, 2022
@mjbvz mjbvz added upstream Issue identified as 'upstream' component related (exists outside of VS Code) javascript JavaScript support issues labels Aug 10, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Sep 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
javascript JavaScript support issues upstream Issue identified as 'upstream' component related (exists outside of VS Code)
Projects
None yet
Development

No branches or pull requests

2 participants