You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Using auto-accessor with readonly or declare should raise an errorΒ #51820
classFoo{
accessor readonlyfoo: number=5;// ^ no error here
accessor declarebar: string;// ^ no error here}constmyc=newFoo();myc.foo=6;// property is not read-only, which is correct because trying to// define it read-only as above should be an error in the first place
π Actual behavior
No TypeScript error is shown, neither for readonly nor for declare. readonly is completely ignored, i.e. writing to the property also does not result in an error.
accessor cannot be used with readonly or declare on the same field declaration.
So I'd expect a corresponding TypeScript error message for both accessor declarations in the example above.
Once using readonly on an accessor raises an error, it is correct to ignore this for further analysis, so the current behavior to not report an error when trying to write to the property is correct and should remain as-is.
Activity
fatcerberus commentedon Dec 8, 2022
I'm a bit confused why
declare accessorwouldn't be legal, butaccessor declareis just weird and looks like an oversight in the parser.RyanCavanaugh commentedon Dec 8, 2022
Yeah, modifier order is always enforced. This is a bug.
fwienber commentedon Dec 12, 2022
That was fast! π