node.js - How do I extend the Error class? -
this code:
let errorbadrequest = new error("bad request"); res.statuscode = 400; errorbadrequest.errors = err.details.reduce(function(prev, current) { prev[current.path] = current.message; return prev; }, {}); throw errorbadrequest;
i wanted extend error
attribute in error instance, tsc said joi-utils.ts(21,23): error ts2339: property 'errors' not exist on type 'error'.
the structure of errors
{fieldname: fieldmsg}
, it's according joi request schema decide.
how solve error typescript compiler? think need declare interface , designate attribute.
property 'errors' not exist on type 'error'.
create file called error-extension.d.ts
, have following:
interface error { errors: error; }
more : https://basarat.gitbooks.io/typescript/content/docs/types/lib.d.ts.html
Comments
Post a Comment