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

JSDoc property modifiers on symbols #60590

Open
VanillaMaster opened this issue Nov 25, 2024 · 0 comments
Open

JSDoc property modifiers on symbols #60590

VanillaMaster opened this issue Nov 25, 2024 · 0 comments

Comments

@VanillaMaster
Copy link

VanillaMaster commented Nov 25, 2024

πŸ”Ž Search Terms

All declarations of '{property}' must have identical modifiers
JSDoc
Symbol
Property Modifiers

πŸ•— Version & Regression Information

This is the behavior in every version I tried (4.X.X - 5.X.X)

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.7.2&filetype=js#code/MYewdgzgLgBA1gIQIYCcYF4YGUCeBbAIxABsAKAIgNXIEoBuAKAeGKQghgDMQQAGGAN4MYImAHoAVBOGiYEmAAEADihBQApsA0ATGaPkKoOJesEwwAV2LEYAHxjQUASzABzGAF89IiWO8BtRFQAXQxzK2I6cTEYAB4AWniYAEFrGG1NVhQkKCdwDhBOGAByQOQUYOKYPAtoGAALJAA3UycMsFzgJBs8EG0nTid1FAgmWVd1WCoUUhpBb1kUSYsUMBgoeqcIMpDGWS9ZSWlZOUUjEzNHF3cD2V9vCEmYadIm7ot1OaET0Q2tnYqYTexA+e1EXi8zFY7C4PAAjPNDlIFgYVGpNDoUWdjKYBOE0vYrm5PCi-LIAPrk6ZhSzWKJiGIJJIAeTgY1EEymqFmiJ+MCWUBWaz+EAAdJTpmCRLcREcsYYcZcoM5iTKfGTRI8uTNgR8vgtfpsxRLUED3uopSSPEA

πŸ’» Code

const kBar = Symbol("bar");

class foo0 {
    /**
     * @protected
     * @type { null | string }
     */
    [kBar] = null; // <-- All declarations of '[kBar]' must have identical modifiers

    get bar() {
        return this[kBar];
    }
    /**
     * @type { string }
     */
    set bar(value) {
        this[kBar] = value;
    }
}

πŸ™ Actual behavior

All declarations of '[kBar]' must have identical modifiers
but if non-symbol key is used, no error occurs

class foo1 {
    /**
     * @protected
     * @type { null | string }
     */
    __bar = null; // <-- Ok

    get bar() {
        return this.__bar;
    }
    /**
     * @type { string }
     */
    set bar(value) {
        this.__bar = value;
    }
}

πŸ™‚ Expected behavior

Symbol key behave same as string key

Additional information about the issue

using exact same annotations on every symbol-property assigment allow avoid this error,
but property type becomes any

const kBar = Symbol("bar");

class foo0 {
    /**
     * @protected
     * @type { null | string }
     */
    [kBar] = null; // <-- Ok

    get bar() {
        return this[kBar];
    }
    /**
     * @type { string }
     */
    set bar(value) {
        /**
         * @protected
         * @type { null | string }
         */
        this[kBar] = value;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant