2016-01-04 14:36:26 +01:00
|
|
|
TypeScript style
|
2015-12-13 18:11:34 +01:00
|
|
|
================
|
|
|
|
|
|
|
|
Basics:
|
|
|
|
- Indent with 2 spaces.
|
|
|
|
- Keep a maximum line length of 120 characters.
|
2016-01-04 14:36:26 +01:00
|
|
|
- Prefer "double quotes" for strings.
|
2015-12-13 18:11:34 +01:00
|
|
|
- Never omit optional semicolons.
|
|
|
|
- Do not put opening braces or brackets on a new line.
|
|
|
|
- Call functions without spaces: foo(bar)
|
|
|
|
- Use 'let' instead of 'var' whenever possible.
|
|
|
|
- Declare "use strict;".
|
|
|
|
- Use rocket (=>) syntax for anonymous functions. If an anonymous function is
|
|
|
|
too long, make it a named function.
|
2016-01-04 14:36:26 +01:00
|
|
|
- Use the strict equality operator (===).
|
2015-12-13 18:11:34 +01:00
|
|
|
- Document functions with JSDoc comments (http://usejsdoc.org).
|
|
|
|
|
2016-01-04 14:36:26 +01:00
|
|
|
|
|
|
|
JavaScript version:
|
|
|
|
Stick with ES6 features. Do not rely on any vendor-specific extensions (such
|
|
|
|
as Firefox often offers). ES6 features not yet supported by major browsers are
|
|
|
|
okay as long as there is a well-supported and reasonable polyfill (such as
|
|
|
|
babel) available.
|
|
|
|
|
|
|
|
|
2015-12-13 18:11:34 +01:00
|
|
|
Names:
|
|
|
|
- Use PascalCase for classes/types, camelCase for variables, functions and
|
|
|
|
properties, UPPER_SNAKE_CASE for constants, kebab-case for event names.
|
2016-01-04 14:36:26 +01:00
|
|
|
- Only capitalize the first letter of an acronym in identifiers (e.g. HttpResponseCode).
|
2015-12-13 18:11:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
APIs:
|
|
|
|
- Prefer 'Promise' to one-shot continuations whenever possible.
|
2016-01-04 14:38:23 +01:00
|
|
|
- Prefer handlebars templates to poking around in the DOM.
|
|
|
|
|
|
|
|
Misc:
|
|
|
|
- Do not use ES6 template strings for constructing HTML,
|
|
|
|
use TSX/JSX literals instead.
|