javascript - How to add debugging information to Error objects when using Flow? -
this common pattern in javascript:
const error = new typeerror('unknown element type'); error.foo = foo; throw error;
(i.e. attach relevant object error instance before throwing it, debugging purposes.)
but flow complains:
property `foo` property not found in typeerror
what's correct solution in flow?
you make subtype of that's more specific:
class subtypeerror extends typeerror { foo : string; constructor(msg){ super(msg); this.foo = ''; } } const error = new subtypeerror('unknown element type'); error.foo = 'hey'; throw error;
though won't work class syntax transformers (like babel class transformer).
Comments
Post a Comment