fix(type): export AV.Error as an interface #667
Merged
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
前景提要:
https://github.com/leancloud/ticket/pull/609/files#diff-dec40c8cf82954eb426791bbfd0c151ce050d78f836fabb5cf4afdaccd1e2566L177
#666
#324
尝试了一下让 AV.Error 继承 Error,发现有难度。一是目前的 AV.Error 支持直接(不用 new 关键字)调用,如果用 ES6 class 那么就是个 breaking change 了。二是就算用 ES6 的继承,babel 6 对 Error 继承也有 bug: babel/babel#8385 (这个版本暂时不想升 babel 7)。
所以最终改了定义文件,避免用户写出
error instanceof AV.Error这样的 type guard。如果用户需要区分出 AV.Error,单独写一个 isAVError 通过判断 error.code 类型作为 type guard。