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
* Fix typo in 'Remove Duplicate Code' section and added union type suggestion
* Make paragraph about `ReadonlyArray<T>` read more fluently
* Remove side effects from function in async/await example
While this is not the point of the example, it would be good to keep the code consistent across examples
* Elaborate capitalization common best practices
* Add mention of `import type` to import section
@@ -580,6 +580,25 @@ function showEmployeeList(employee: Developer | Manager) {
580
580
}
581
581
```
582
582
583
+
You may also consider adding a union type, or common parent class if it suits your abstraction.
584
+
```ts
585
+
classDeveloper {
586
+
// ...
587
+
}
588
+
589
+
classManager {
590
+
// ...
591
+
}
592
+
593
+
typeEmployee=Developer|Manager
594
+
595
+
function showEmployeeList(employee:Employee[]) {
596
+
// ...
597
+
});
598
+
}
599
+
600
+
```
601
+
583
602
You should be critical about code duplication. Sometimes there is a tradeoff between duplicated code and increased complexity by introducing unnecessary abstraction. When two implementations from two different modules look similar but live in different domains, duplication might be acceptable and preferred over extracting the common code. The extracted common code, in this case, introduces an indirect dependency between the two modules.
584
603
585
604
**[⬆ back to top](#table-of-contents)**
@@ -1274,15 +1293,15 @@ interface Config {
1274
1293
}
1275
1294
```
1276
1295
1277
-
Case of Array, you can create a read-only array by using `ReadonlyArray<T>`.
1278
-
do not allow changes such as `push()` and `fill()`, but can use features such as `concat()` and `slice()` that do not change the value.
1296
+
For arrays, you can create a read-only array by using `ReadonlyArray<T>`.
1297
+
It doesn't allow changes such as `push()` and `fill()`, but can use features such as `concat()` and `slice()` that do not change the array's value.
1279
1298
1280
1299
**Bad:**
1281
1300
1282
1301
```ts
1283
1302
const array:number[] = [ 1, 3, 5 ];
1284
1303
array= []; // error
1285
-
array.push(100); // array will updated
1304
+
array.push(100); // array will be updated
1286
1305
```
1287
1306
1288
1307
**Good:**
@@ -2343,15 +2362,15 @@ import { promisify } from 'util';
Prefer using `PascalCase` for class, interface, type and namespace names.
2562
2584
Prefer using `camelCase` for variables, functions and class members.
2585
+
Prefer using capitalized `SNAKE_CASE` for constants.
2563
2586
2564
2587
**[⬆ back to top](#table-of-contents)**
2565
2588
@@ -2660,6 +2683,7 @@ With clean and easy to read import statements you can quickly see the dependenci
2660
2683
- Unused imports should be removed.
2661
2684
- Named imports must be alphabetized (i.e. `import {A, B, C} from 'foo';`)
2662
2685
- Import sources must be alphabetized within groups, i.e.: `import * as foo from 'a'; import * as bar from 'b';`
2686
+
- Prefer using `import type` instead of `import` when importing only types from a file to avoid dependency cycles, as these imports are erased at runtime
2663
2687
- Groups of imports are delineated by blank lines.
2664
2688
- Groups must respect following order:
2665
2689
- Polyfills (i.e. `import 'reflect-metadata';`)
@@ -2674,6 +2698,7 @@ With clean and easy to read import statements you can quickly see the dependenci
0 commit comments