#Why does Type of "Error" class only accept one parameter? Javascript allows it two

3 messages · Page 1 of 1 (latest)

sweet badger
#

For some reason when trying to add a second parameter to error class constructor typescript gives me an error and says that it only accepts 1 argument.

bronze sky
#

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
    }
}
jovial ember