New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operator Overloads #5407

Antony-Jones opened this Issue Oct 26, 2015 · 3 comments


None yet
4 participants

Antony-Jones commented Oct 26, 2015

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


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

This comment has been minimized.


DanielRosenwasser commented Oct 26, 2015

One thing we avoid doing is type-driven emit. The idea is that TypeScript types have no bearing at runtime - the code is as close to the analogous JavaScript that you would have written. Given that, substituting in a method call for an operator would go against that.

Apart from that, this is related to #2319, so I'm going to close this as a duplicate.


This comment has been minimized.

nitinbansal1989 commented Nov 10, 2016

i have written an ORM framework in typescript. Its still new and only supports mysql currently. Its architecture is based on entity framework.
Enabling Operator Overloading will support the creating of 'LINQ' like queries.
You can add this feature as a optional extension like Decorators feature with experimental implementation and compiler option. Hope to see this in typescript.


This comment has been minimized.

jay3sh commented Aug 11, 2017

I'm developing numpy like library in typescript (bluemath). Operator overloading will significantly improve the interface of my NDArray class.

@Microsoft Microsoft locked and limited conversation to collaborators Jun 19, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.