-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Design Meeting Notes, 8/13/2024 #59624
Comments
Thanks for discussing this! The original issue highlights inconsistency for target emit across ES2021 and beyond. The notes here suggest a solution of deprecating the ability to set Taken literally, that would provide consistency for target emit >= ES2022 but would leave everything earlier defaulting to the legacy behavior. Is the suggested deprecation intended to go further and imply that |
If parameter properties might be deprecated, is there a canonical reference for that idea? And is it related at all to other non-standard runtime features like namespaces and enums (outside of their overlap with https://github.com/rbuckton/proposal-enum)? I ask because it came up in a discussion about Node's recent |
Parameter properties are not deprecated. What we are considering deprecating is We have some interest in investigating parameter properties as a TC39 proposal in the future. |
@rbuckton ah, thanks for the clarification |
Yes, that would be the intention. It should be noted that even under |
I must say I'm shocked! This all reads as if you're willing to break a lot of codebases! Please see my feedback below, which is from the point of view of a TS power user who's been working on a very large (and private) Angular powered code base (owned by a Swiss insurance company) starting with TS 2.x
I suppose you're referring to #55028?
This is a HUGE breaking change for a lot of projects that are using Constructor Dependency Injection in combination with parameter properties in case they want to access the injected services during instantiation (which is a common thing to do with RxJS and/or NgRx and I'm sure lots of other libraries as well) - the most common case being to avoid using methods that return distinct object identities every time they're called. Instead it's often desirable to have a single fixed object (e.g. observable) assigned during instantiation that will not mess around with change detection. By changing the order (and planning to deprecate any way to switch back to the old order, except for quirky workarounds, see below) you're effectively deprecating Constructor Dependency Injection, as Angular (e.g.) used to have it since the very beginnings. This brings me to reason No. 2 why your experiment is inaccurate:
One might be tempted to ask now: if there are so many private enterprise projects that could run into problems: why haven't we got more people participating in reporting this? I can think of two reasons why:
No. I see it differently: It has been introduced (with TS 3.7, Nov 2019) as a preparatory means to allow people to adhere to the upcoming standard. It was meant for users to actively set it to Besides that: Exactly! Why break people? Why breaking my "legacy" code base that's relying on the order of execution being "parameter properties" first, class fields second, constructor body third.
I'm not sure. Is this your proposed solution for old codebases to work around that breaking change of removing
Here's an alternative plan that's far more DX friendly:
Final remark:Angular has been somewhat promoting the new
If nothing changes (i.e. if you stick with the described plan of deprecating |
In order to execute parameter properties before class field initializers, all class field initialization would have to be transformed to be done in the constructor after the fields induced by parameter properties are set. That could work with decorators as long as decorators are downleveled, but removing the initializer expressions would be visible with native decorators, so using parameter properties would mean forever downleveling decorators. Those are big emit changes to have happen because you use parameter properties. And if parameter properties were standardized, there's no guarantee that they would have the same ordering wrt class fields as TypeScript. |
Ordering Parameter Properties and Class Fields
#45995
When we adjusted our class field emit (with
useDefineForClassFields
), we also adjusted the relative ordering of class fields and parameter properties.Under JS, class fields run before the body of the constructor.
Under TS, previously, class fields ran after parameter properties, but before the body of the constructor.
Under
useDefineForClassFields
we error on any access to parameter properties, but otherwise it's fine.Should we adjust the ordering to be consistent?
useDefineForClassFields
was introduced as a legacy behavior to avoid breaks, why break people?We could run a PR where it always errors, see what breaks.
Is there something clever we could do with emit?
The tough part is that most codebases that would be affected by running on GitHub won't be uncovered. Typically these are more mature codebases.
Could always do a codemod. We typically rely on quick fixes here.
Some of us feel like it's a good idea to get consistent emit. Picking a date in the future to deprecate and eventually remove is the proposed plan. But need to experiment first.
Maybe 6.0 deprecation is the plan.
This has only been available since ES2022 though!
6.0 deprecation = 6.5 removal, which is just over 2 years from now.
Aside: we should investigate parameter properties in ECMAScript.
The text was updated successfully, but these errors were encountered: