forked from mei23/misskey-v11
-
Notifications
You must be signed in to change notification settings - Fork 5
en_US: cont_TypeScript Coding Conventions
Komohachi Fujishiki edited this page Apr 4, 2022
·
1 revision
This is to avoid Automatic Semicolon Insertion (ASI) hazard.
Ref:
- https://www.ecma-international.org/ecma-262/#sec-automatic-semicolon-insertion
- https://github.com/tc39/ecma262/pull/1062
Bad:
if (foo)
bar;
else
baz;
Good:
if (foo) {
bar;
} else {
baz;
}
As a special case, you can omit the curly brackets if
- the body of the
if
-statement have only one statement and, - the
if
-statement does not haveelse
-clause.
Good:
if (foo) bar;
Make sure that the condition and the body statement are on the same line.
Bad:
if (foo.length)
Good:
if (foo.length > 0)
This is because the current language support does not work well with export default
.
Ref:
- https://basarat.gitbooks.io/typescript/docs/tips/defaultIsBad.html
- https://gfx.hatenablog.com/entry/2017/11/24/135343
Bad:
export default function(foo: string): string {
Good:
export function something(foo: string): string {