@@ -651,20 +651,43 @@ a(href="#toc") Back to top
651
651
652
652
.s-rule.do
653
653
:marked
654
- **Do** use uppercase with underscores when naming constants .
654
+ **Do** declare variables with `const` if their values should not change during the application lifetime .
655
655
656
656
.s-why
657
657
:marked
658
- **Why?** Follows conventional thinking for constants .
658
+ **Why?** Conveys to readers that the value is invariant .
659
659
660
660
.s-why.s-why-last
661
661
:marked
662
- **Why?** Constants can easily be identified.
662
+ TypeScript helps enforce that intent by requiring immediate initialization and by
663
+ preventing subsequent re-assignment.
664
+
665
+ .s-rule.consider
666
+ :marked
667
+ **Consider** spelling `const` variables in lower camel case.
663
668
664
- + makeExample('style-guide/ts/03-02/app/shared/data.service.avoid.ts' , 'example' , 'app/shared/data.service.ts' )( avoid =1 )
665
- :marked
669
+ .s-why
670
+ :marked
671
+ **Why?** lower camel case variable names (`heroRoutes`) are easier to read and understand
672
+ than the traditional UPPER_SNAKE_CASE names (`HERO_ROUTES`).
673
+
674
+ .s-why.s-why-last
675
+ :marked
676
+ **Why?** The tradition of naming constants in UPPER_SNAKE_CASE reflects
677
+ an era before the modern IDEs that quickly reveal the `const` declaration.
678
+ TypeScript itself prevents accidental reassignment.
679
+
680
+ .s-rule.do
681
+ :marked
682
+ **Do** tolerate _existing_ `const` variables that are spelled in UPPER_SNAKE_CASE.
683
+
684
+ .s-why.s-why-last
685
+ :marked
686
+ **Why?** Although we recommend creating _new_ constants in lower camel case,
687
+ the tradition of UPPER_SNAKE_CASE remains popular and pervasive,
688
+ especially in third party modules.
666
689
667
- + makeExample('style-guide/ts/03-02/app/shared/data.service.ts' , 'example ' , 'app/shared/data.service.ts' )
690
+ + makeExample('style-guide/ts/03-02/app/shared/data.service.ts' , '' , 'app/shared/data.service.ts' )
668
691
:marked
669
692
670
693
a( href ="#toc" ) Back to top
0 commit comments