index.d.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. Create an error from multiple errors.
  3. */
  4. declare class AggregateError<T extends Error = Error> extends Error implements Iterable<T> {
  5. readonly name: 'AggregateError';
  6. /**
  7. @param errors - If a string, a new `Error` is created with the string as the error message. If a non-Error object, a new `Error` is created with all properties from the object copied over.
  8. @returns An Error that is also an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators#Iterables) for the individual errors.
  9. @example
  10. ```
  11. import AggregateError = require('aggregate-error');
  12. const error = new AggregateError([new Error('foo'), 'bar', {message: 'baz'}]);
  13. throw error;
  14. // AggregateError:
  15. // Error: foo
  16. // at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:33)
  17. // Error: bar
  18. // at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13)
  19. // Error: baz
  20. // at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13)
  21. // at AggregateError (/Users/sindresorhus/dev/aggregate-error/index.js:19:3)
  22. // at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13)
  23. // at Module._compile (module.js:556:32)
  24. // at Object.Module._extensions..js (module.js:565:10)
  25. // at Module.load (module.js:473:32)
  26. // at tryModuleLoad (module.js:432:12)
  27. // at Function.Module._load (module.js:424:3)
  28. // at Module.runMain (module.js:590:10)
  29. // at run (bootstrap_node.js:394:7)
  30. // at startup (bootstrap_node.js:149:9)
  31. for (const individualError of error) {
  32. console.log(individualError);
  33. }
  34. //=> [Error: foo]
  35. //=> [Error: bar]
  36. //=> [Error: baz]
  37. ```
  38. */
  39. constructor(errors: ReadonlyArray<T | {[key: string]: any} | string>);
  40. [Symbol.iterator](): IterableIterator<T>;
  41. }
  42. export = AggregateError;