Skip to content

Commit 35fff07

Browse files
committed
Accept an Array instead of an Iterable
Accepting an Iterable sounded good in theory, but in practice it's just easier to only accept an Array and if users have an Iterable, they can just spread it.
1 parent 4135565 commit 35fff07

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

index.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ const cleanInternalStack = stack => stack.replace(/\s+at .*aggregate-error\/inde
66

77
class AggregateError extends Error {
88
constructor(errors) {
9-
// Even though strings are iterable, we don't allow them to prevent subtle user mistakes
10-
if (!errors[Symbol.iterator] || typeof errors === 'string') {
11-
throw new TypeError(`Expected input to be iterable, got ${typeof errors}`);
9+
if (!Array.isArray(errors)) {
10+
throw new TypeError(`Expected input to be an Array, got ${typeof errors}`);
1211
}
1312

1413
errors = [...errors].map(error => {

readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Returns an `Error` that is also an [`Iterable`](https://developer.mozilla.org/en
5555

5656
#### errors
5757

58-
Type: `Iterable<Error|Object|string>`
58+
Type: `Array<Error|Object|string>`
5959

6060
If a string, a new `Error` is created with the string as the error message.<br>
6161
If a non-Error object, a new `Error` is created with all properties from the object copied over.

0 commit comments

Comments
 (0)