Created
September 15, 2020 00:23
-
-
Save kxxoling/c714b58bb31fd3d4e67da3ae06f07eda to your computer and use it in GitHub Desktop.
Revisions
-
kxxoling created this gist
Sep 15, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ // From https://zhuanlan.zhihu.com/p/113019880 // 使用 BaseError 当作 base Error class class BaseError extends Error { constructor(message: string) { super(message); this.name = new.target.name; if (typeof (Error as any).captureStackTrace === 'function') { (Error as any).captureStackTrace(this, new.target); } if (typeof Object.setPrototypeOf === 'function') { Object.setPrototypeOf(this, new.target.prototype); } else { (this as any).__proto__ = new.target.prototype; } } } // 使用例子 class MyError extends BaseError { // ... }