77db1fd0a25cf63e93c26d3afeb4a6895af7b2a2a62d9bcf1a72da883330b1cfe21b43286428d11964364c1ff7dbf5d44653be30c5c027528efda061269e72 789 B

1234567891011121314151617181920
  1. /**
  2. * Used to create Error subclasses until the community moves away from ES5.
  3. *
  4. * This is because compiling from TypeScript down to ES5 has issues with subclassing Errors
  5. * as well as other built-in types: https://github.com/Microsoft/TypeScript/issues/12123
  6. *
  7. * @param createImpl A factory function to create the actual constructor implementation. The returned
  8. * function should be a named function that calls `_super` internally.
  9. */
  10. export function createErrorClass<T>(createImpl: (_super: any) => any): T {
  11. const _super = (instance: any) => {
  12. Error.call(instance);
  13. instance.stack = new Error().stack;
  14. };
  15. const ctorFunc = createImpl(_super);
  16. ctorFunc.prototype = Object.create(Error.prototype);
  17. ctorFunc.prototype.constructor = ctorFunc;
  18. return ctorFunc;
  19. }