You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/styleguide/styleguide.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
-
# TypeScript StyleGuide and Coding Conventions
1
+
# TypeScript Style Guide and Coding Conventions
2
2
3
-
> An unofficial TypeScript StyleGuide
3
+
> An unofficial TypeScript Style Guide
4
4
5
-
People have asked me for my opinions on this. Personally I don't enforce these a lot on my teams and projects but it does help to have these mentioned as a tie breaker when someone feels the need to have such strong consistency. There are other things that I feel much more strongly about and those are covered in the [tips chapter](../tips/main.md) (e.g. type assertion is bad, property setters are bad) 🌹.
5
+
People have asked me for my opinions on this. Personally I don't enforce these a lot on my teams and projects but it does help to have these mentioned as a tiebreaker when someone feels the need to have such strong consistency. There are other things that I feel much more strongly about and those are covered in the [tips chapter](../tips/main.md) (e.g. type assertion is bad, property setters are bad) 🌹.
6
6
7
7
Key Sections:
8
8
@@ -170,7 +170,7 @@ let foo = {x:123,y:undefined};
170
170
let foo:{x:number,y?:number} = {x:123};
171
171
```
172
172
173
-
* Use `undefined` in general (do consider returning an object like `{valid:boolean,value?:Foo}` instead)
173
+
* Use `undefined` in general (do consider returning an object like `{valid:boolean,value?:Foo}` instead)
174
174
175
175
***Bad***
176
176
```ts
@@ -181,7 +181,7 @@ return null;
181
181
returnundefined;
182
182
```
183
183
184
-
* Use `null` where its a part of the API or conventional
184
+
* Use `null` where it's a part of the API or conventional
185
185
186
186
> Reason: It is conventional in Node.js e.g. `error` is `null` for NodeBack style callbacks.
187
187
@@ -205,7 +205,7 @@ if (error === null)
205
205
if (error)
206
206
```
207
207
208
-
* Use `== null` / `!= null` (not `===` / `!==`) to check for `null` / `undefined` on primitives as it works for both `null`/`undefined` but not other falsy values (like `''`,`0`,`false`) e.g.
208
+
* Use `== null` / `!= null` (not `===` / `!==`) to check for `null` / `undefined` on primitives as it works for both `null`/`undefined` but not other falsy values (like `''`,`0`,`false`) e.g.
209
209
210
210
**Bad**
211
211
```ts
@@ -219,7 +219,7 @@ if (error != null) // rules out both null and undefined
219
219
## Formatting
220
220
The TypeScript compiler ships with a very nice formatting language service. Whatever output it gives by default is good enough to reduce the cognitive overload on the team.
221
221
222
-
Use [`tsfmt`](https://github.com/vvakame/typescript-formatter) to automatically format your code on the command line. Also your IDE (atom/vscode/vs/sublime) already has formatting support built-in.
222
+
Use [`tsfmt`](https://github.com/vvakame/typescript-formatter) to automatically format your code on the command line. Also, your IDE (atom/vscode/vs/sublime) already has formatting support built-in.
223
223
224
224
Examples:
225
225
```ts
@@ -231,7 +231,7 @@ const foo: string = "hello";
231
231
232
232
* Prefer single quotes (`'`) unless escaping.
233
233
234
-
> Reason: More JavaScript teams do this (e.g. [airbnb](https://github.com/airbnb/javascript), [standard](https://github.com/feross/standard), [npm](https://github.com/npm/npm), [node](https://github.com/nodejs/node), [google/angular](https://github.com/angular/angular/), [facebook/react](https://github.com/facebook/react)). Its easier to type (no shift needed on most keyboards). [Prettier team recommends single quotes as well](https://github.com/prettier/prettier/issues/1105)
234
+
> Reason: More JavaScript teams do this (e.g. [airbnb](https://github.com/airbnb/javascript), [standard](https://github.com/feross/standard), [npm](https://github.com/npm/npm), [node](https://github.com/nodejs/node), [google/angular](https://github.com/angular/angular/), [facebook/react](https://github.com/facebook/react)). It's easier to type (no shift needed on most keyboards). [Prettier team recommends single quotes as well](https://github.com/prettier/prettier/issues/1105)
235
235
236
236
> Double quotes are not without merit: Allows easier copy paste of objects into JSON. Allows people to use other languages to work without changing their quote character. Allows you to use apostrophes e.g. `He's not going.`. But I'd rather not deviate from where the JS Community is fairly decided.
237
237
@@ -255,7 +255,7 @@ const foo: string = "hello";
255
255
256
256
* Annotate arrays as `foos:Foo[]` instead of `foos:Array<Foo>`.
257
257
258
-
> Reasons: Its easier to read. Its used by the TypeScript team. Makes easier to know something is an array as the mind is trained to detect `[]`.
258
+
> Reasons: It's easier to read. It's used by the TypeScript team. Makes easier to know something is an array as the mind is trained to detect `[]`.
259
259
260
260
## Filename
261
261
Name files with `camelCase`. E.g. `accordion.tsx`, `myControl.tsx`, `utils.ts`, `map.ts` etc.
@@ -269,7 +269,7 @@ Name files with `camelCase`. E.g. `accordion.tsx`, `myControl.tsx`, `utils.ts`,
269
269
```
270
270
type Foo = number | { someProperty: number }
271
271
```
272
-
* Use `interface` when you want `extends` or `implements` e.g
272
+
* Use `interface` when you want `extends` or `implements` e.g.
0 commit comments