-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fix #7590: Allow 'readonly' to be used in constructor parameters #8555
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
Conversation
Hi @Andy-MS, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!
TTYL, MSBOT; |
AccessibilityModifier = Public | Private | Protected, | ||
// Accessibility modifiers and 'readonly' can be attached to a parameter in a constructor to make it a property. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The term for this is a "parameter property", so maybe a better name for the flag would be ParameterPropertyModifier
@@ -407,8 +407,10 @@ namespace ts { | |||
HasAggregatedChildData = 1 << 29, // If we've computed data from children and cached it in this node | |||
HasJsxSpreadAttribute = 1 << 30, | |||
|
|||
Modifier = Export | Ambient | Public | Private | Protected | Static | Abstract | Default | Async, | |||
Modifier = Export | Ambient | Public | Private | Protected | Static | Abstract | Default | Async | Readonly, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you still want to keep Readonly
in ? since you have made a new flag ParameterPropertyModifier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is a modifier..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got cha, I got confused why it is here caz i thought it is not direct related with the bug.
I believe that TypeScript Spec should be updated to include this change |
@@ -0,0 +1,13 @@ | |||
class C { | |||
constructor(readonly x: number) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also to clarify if it is just readonly
without accessibility modifier, are we assuming it is public
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. This is the same as for properties. (class C { readonly x: number; }
)
Can you add a test for declaration emitter. i.e. |
Also a test for:
|
Please add the word doc updates to the spec as well. |
👍 |
I think it'd be better to just file a spec bug and assign it to me or Anders. |
…bilityModifier to detect parameter properties. This is a continuation of #8555.
Fixes #7590