Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Changing inherited functions typescript

Is there any way to override the contents of the asString function in my RunTimeError class as I need the error message to be different than the one in my generic Error class

class Error {
    errorName: string;
    details: string;
    posStart: Position;
    posEnd: Position;

    constructor({errorName, details, posStart, posEnd}: ErrorTypes) {
        this.errorName = errorName
        this.details = details
        this.posStart = posStart
        this.posEnd = posEnd
    }

    asString() {
        let result: string = `${this.errorName} on line ${this.posStart.ln+1}: ${this.details}`
        return result
    }
}
class RunTimeError extends Error {
    context: any

    constructor({details, posStart, posEnd, context}: SubErrorTypes) {
        super({errorName:"Runtime Error", details:details, posStart:posStart, posEnd:posEnd})
        this.context = context
    }

    //change contents of asString
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

pass a prop into the generic class function asString

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading