Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Operator Overloads #5407

Copy link
Copy link
@Antony-Jones

Description

@Antony-Jones
Issue body actions

It would simplify a lot of use cases if we could override relational, equality, additive, and Multiplicative operators.

My initial thoughts on how this would work is that functions would replace the operators with functions when compiling to JavaScript.

class MyClass {
    constructor() {
    }

    public Operator > (value: any):boolean {
        // compare value
    }
}

var myClass = new MyClass();

if(myClass > otherValue){
    // Do stuff
}

Becomes:

var MyClass = (function () {
    function MyClass() {
    }
    MyClass.prototype.greaterThan = function (value) {
        // compare value
    };
    return MyClass;
})();
var myClass = new MyClass();
if (myClass.greaterThan(otherValue) {
    // do Stuff
}
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionDuplicateAn existing issue was already createdAn existing issue was already createdOut of ScopeThis idea sits outside of the TypeScript language design constraintsThis idea sits outside of the TypeScript language design constraints

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.