Rules to enforce coding standards
Every coding project should have a document that states what coding rules will be enforced during a code review. Tools called “linters” are good at detecting these rules. They need to be activated at the start of a project to ensure everyone is on the same page. Several rules can be activated in a TypeScript project. The first is called strict mode.
Strict mode
JavaScript has a strict mode feature. Adding "use strict"
as the first line of a JavaScript source file enables extra rules to ensure good coding practices are followed that avoid subtle code errors.
This includes forcing variables to be explicitly declared with a let
, var
, or const
keyword. TypeScript has a similar strict mode that can further force all variables to be assigned a type, such as string
, number
, or boolean
. This is to avoid implicitly assigning a variable to the any
type, which can lead to type coercion issues:
Figure...