#Why does Type of "Error" class only accept one parameter? Javascript allows it two
3 messages · Page 1 of 1 (latest)
If you want to store custom data on an error object in typescript, you'll need to create a custom error class that extends the base Error class with your new property:
type MyErrorProps = {
cause: string
}
class MyError extends Error {
props: MyErrorProps
constructor(message: string, props: MyErrorProps) {
super(message)
this.props = props
}
}
its part of Error since es2022: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause