In TypeScript how can I declare class method synonym

0 votes

I want to define class method which is supposed to do the same as other class method and return the same value. Something like that:

class Thing {
    _description : string
    description( new_desc : string ) : Thing {
        this._description = new_desc
        return this
    }

    /** And here I want to define method which is doing absolutely the same and
        returning the same value, but targeting API users that are lazy to type.*/
    desc( ? ) {
        ?
    }
}

In plain JavaScript I would do it like this:

class Thing {
    _description
    description( new_desc ) {
        this._description = new_desc
        return this
    }

    desc() {
        return this.description.apply( this, arguments )
    }
}

But it obviously breaks all the types inference and safety.

How can I do it in TypeScript to ensure type-safety?

Jul 18, 2022 in TypeSript by Logan
• 2,140 points

edited 5 days ago 7 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP