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/rules/no-promise-reject.md
+8-7Lines changed: 8 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,15 @@
1
-
# Disallow try-catch[-finally] and try-finally patterns (`functional/no-promise-reject`)
1
+
# Disallow rejecting promises
2
2
3
3
<!-- end auto-generated rule header -->
4
4
5
5
This rule disallows use of `Promise.reject()`.
6
6
7
-
We don't recommend this rule but it's there for those who want it.
8
-
9
7
## Rule Details
10
8
11
-
You can view a `Promise` as a result object with built-in error (something like `{ value: T } | { error: Error }`) in which case a rejected `Promise` can be viewed as a returned result and thus fits with functional programming.
12
-
You can also view a rejected promise as something similar to an exception and as such something that does not fit with functional programming.
13
-
If your view is the latter you can use the `no-promise-reject` rule to disallow rejected promises.
9
+
It is useful when using an `Option` type (something like `{ value: T } | { error: Error }`)
10
+
for handling errors. In this case a promise should always resolve with an `Option` and never reject.
11
+
12
+
This rule should be used in conjunction with [`no-throw-statements`](./no-throw-statements.md).
14
13
15
14
### ❌ Incorrect
16
15
@@ -36,6 +35,8 @@ async function divide(x, y) {
36
35
asyncfunctiondivide(x, y) {
37
36
const [xv, yv] =awaitPromise.all([x, y]);
38
37
39
-
return yv ===0?newError("Cannot divide by zero.") : xv / yv;
0 commit comments