Error cause

Specification
Proposal repo

Built-ins signatures

class Error {
  constructor(message: string, { cause: any }): %Error%;
}

class [
  EvalError,
  RangeError,
  ReferenceError,
  SyntaxError,
  TypeError,
  URIError,
  WebAssembly.CompileError,
  WebAssembly.LinkError,
  WebAssembly.RuntimeError,
] extends Error {
  constructor(message: string, { cause: any }): %Error%;
}

class AggregateError extends Error {
  constructor(errors: Iterable, message?: string, { cause: any }?): AggregateError;
  cause: any;
}

Entry points

core-js/proposals/error-cause

TypeScript type definitions

@core-js/types/proposals/error-cause

Example

const cause = new TypeError('Something wrong');
const error = new TypeError('Here is what went wrong', { cause });
error.cause === cause; // => true