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

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -