Skip to content

allow super() constructor call inline, like in c# #12120

@parliament718

Description

@parliament718

Is there any reason why Typescript can't support a little syntax sugar similar to C# in allowing the base constructor call to be made inline? So Instead of:

class Car extends Machine {
    constructor(radiator: RadiatorMechanism) {
        super();                                 <- eww, please add sugar
        var engine = EngineFactory.createEngine('V8');
      
    }
}

it could be:

//aaah, much better      
class Car extends Machine {
    constructor(radiator: RadiatorMechanism): super() {
        var engine = EngineFactory.createEngine('V8'); 
    }
}

It's pretty trivial because all it does is clean up the constructor body, (especially when the following line is really long it just looks weird and my OCD kicks in), but usually that's exactly what syntax sugar is for.

For whatever other reasons it has support in C#, I petition for its support in Typescript ✌️

Metadata

Metadata

Assignees

No one assigned

    Labels

    Out of ScopeThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions