Skip to content

Commit

Permalink
Accept an Array instead of an Iterable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sindresorhus committed Dec 26, 2018
1 parent 4135565 commit 35fff07
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ const cleanInternalStack = stack => stack.replace(/\s+at .*aggregate-error\/inde

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

errors = [...errors].map(error => {
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Returns an `Error` that is also an [`Iterable`](https://developer.mozilla.org/en

#### errors

Type: `Iterable<Error|Object|string>`
Type: `Array<Error|Object|string>`

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

0 comments on commit 35fff07

Please sign in to comment.