Open
Description
opened on 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
π» 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