5

Closed

Explicit Return Types On Properties Creates Bad Code

description

Given the following typescript:
class Result { }

class Test
{
    get Property(): Result
    {
        var x = 1;
        return null;
    }
}
The following JavaScript is generated:
var Result = (function () {
    function Result() {
    }
    return Result;
})();

var Test = (function () {
    function Test() {
    }
    Object.defineProperty(Test.prototype, "Property", {
        get: function () {
            this.x = 1;;
            return null;
        },
        enumerable: true,
        configurable: true
    });
    return Test;
})();
The broken line is "this.x = 1;;", which should be "var x = 1;". If I get rid of the explicit return type on the getter, it compiles as expected.


This affects the current 0.9 release.
Closed Jun 27, 2013 at 7:35 PM by billti

comments

billti wrote Jun 19, 2013 at 6:57 AM

Great catch. Thank you very much for reporting. This is indeed strange and incorrect behavior. We'll take a look and see what's going on.

Orbifold wrote Jun 25, 2013 at 5:58 PM

Similar effect in a for-loop reported here.

billti wrote Jun 27, 2013 at 7:35 PM

billti wrote Jun 29, 2013 at 12:23 AM