firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

Remove prototype overrides in `FirebaseError` and all subclasses

Open dlarocque opened this issue 4 months ago • 3 comments

We override the prototype of this in all of the constructors for our custom error classes. This allowed us to adjust the prototype chain, so that we can perform instanceof checks on subclasses of Error.

Since ES2015, the built-in Error constructor uses new.target to adjust the prototype chain for us, so we no longer need to do it ourselves.

See https://github.com/Microsoft/TypeScript-wiki/blob/main/Breaking-Changes.md#extending-built-ins-like-error-array-and-map-may-no-longer-work (the link doesn't work well since the linked header is hidden behind a rolled up section that can be expanded by clicking "See Changes for Older Releases" at the bottom).

Since new.target does not exist in ES5, the prototype chain won't be adjusted if our bundle is transpiled down to ES5.

dlarocque avatar Sep 30 '24 18:09 dlarocque