Skip to content

JSDoc property modifiers on symbolsΒ #60590

Open
@VanillaMaster

Description

πŸ”Ž 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;
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions