- Use TypeScript
- Use the latest stable JavaScript syntax with a transpiler, such as babel.
- Use ESLint and Prettier for auto-formatting and auto-fixing
- Use Jest for unit testing
- Prefer ES6 classes over prototypes.
- Use strict equality checks (
===
and!==
) except when comparing against (null
orundefined
). - Prefer arrow functions
=>
, over thefunction
keyword except when defining classes or methods. - Prefer ES6 destructuring over object literal notation.
- Use ES6 spread and rest operator wherever possible for a cleaner code.
- Use
PascalCase
for classes,lowerCamelCase
for variables and functions,SCREAMING_SNAKE_CASE
for constants,_singleLeadingUnderscore
for private variables and functions. - Prefer template strings over string concatenation.
- Prefer promises over callbacks.
- Prefer array functions like
forEach
,map
,filter
andreduce
overfor/while
loops. - Use
const
for declaring variables that will never be re-assigned, andlet
otherwise. - Avoid
var
to declare variables. - Prefer async/await over traditional promise syntax
- Use the Nullish coalescing operator
??
- Use TypeScript in strict mode
- Prefer Functions over Classes
- Use
PascalCase
for Interfaces and Type Aliases - Use readonly properties where applicable
- Use const Assertions where applicable to avoid type widening
- Avoid Mixins
- Avoid Decorators
- Avoid Overloading Functions
- Prefer Optional Properties in an interface rather than declaring the
property type as
T | undefined
- Prefer explicitly defining interfaces over Extending Interfaces
- Avoid the use of the any type
- Avoid the Non-null assertion operator
- Avoid Type Assertions
- Prefer the
as
-syntax for Type Assertions over the angle-bracket syntax - Prefer Type Guards over Type Assertions
- Prefer Union Types, Lookup Types, Mapped Types and const Assertions over Enums
- Prefer arrow functions
=>
, over thefunction
keyword except when using Generics
-
Use Prettier defaults with the following additional configuration (.prettierrc):
{ "singleQuote": true }
This configuration includes:
If ESLint is used along with Prettier, the ESLInt plugin eslint-config-prettier should also be used to turn off all ESLint style rules that are already handled by Prettier.