- Notifications
You must be signed in to change notification settings - Fork27k
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Thanks everyone for your feedback on the style guide RFC! Overall, reception to revising the style guide has been very positive. The change that generated the most feedback (unsurprisingly) was the update around naming and suffixes. Based on feedback, we're planning to adjust the proposal as follows:
This will allow tooling to identify Angular-specific files without needing to examine the file contents. Aside from these points, we're planning to move forward with the rest of the proposed style changes. This doesn't mean the the revised style guide will be set in stone for all eternity— moving forward, we'll be attempting to make smaller, more incremental updates the style guide as we continue to improve the framework. The next steps for the team:
Thanks! |
BetaWas this translation helpful?Give feedback.
All reactions
👍 125👎 133🎉 14😕 44❤️ 16🚀 17
Replies: 1 comment
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Hey everyone, we're back foranother update on this style guide. From vote responses on the RFC response, social media, and people just telling us (outside of this RFC), we've received feedback that people strongly prefernot introducing the Additionally, we'readding one new recommendation:Prefer the We're adding this new recommendation in light of the introduction ofclass fields in ECMAScript 2022. Previously, class fields were purely a TypeScript feature that were compiled into property assignments in the class's constructor. Native class fields, however, have different semantics than this earlier behavior— class field initializers runbefore the class's constructor. This particularly impacts how you can use class fields with injected dependencies. To demonstrate, here's an example using constructor parameter injection: @Component({/* ... */})exportclassUserProfile{privateuser=this.userData.getCurrent();constructor(privateuserData:UserData){}} This example works just fine when TypeScript emits ECMAScript versions less than ES2022. In these versions, the compiled JavaScript looks like this: // Emitting ES2017exportclassUserProfile{constructor(userData){// The field initializer is inlined into the constructorthis.userData=userData;this.user=this.userData.getCurrent();}} However, in ES2022 with the // Emitting ES2022exportclassUserProfile{userData;user=this.userData.getCurrent();// Error! userData is not yet initialized!constructor(userData){this.userData=userData;}} This output throws an error because the field initializer runsbefore the constructor and tries to use the injected dependency before it's available. To work around this with constructor injection, you would write your code like this: @Component({/* ... */})exportclassUserProfile{// Field declaration is separated from initialization.privateuser:User;constructor(privateuserData:UserData){this.user=userData.getCurrent();}} Many developers find the separation of field declaration and initialization to be undesirable. Fortunately, the @Component({/* ... */})exportclassUserProfile{privateuserData=inject(UserData);privateuser=userData.getCurrent();} The All the other proposed changes in the original RFC will proceed as planned. Thanks for being invested in code style! |
BetaWas this translation helpful?Give feedback.
All reactions
👍 51🎉 15😕 3👀 2