Skip to content

Dynamically bound this not being generated within switch statements as of 1.8.0-dev.20151110 #5637

Description

@myitcv

This is as minimal an example as I have for now (tsc version and tsconfig.json details at the bottom of this issue)

class A {
    doIt(x: Array<string>): void {
        x.forEach((v) => {
            switch(v) {
                case "test": console.log(this);
            }
        });
    }
}

Comparing the transpiled output from 1.8.0-dev.20151109 and 1.8.0-dev.20151110 we see:

--- app.js.1.8.0-dev.20151109   2015-11-12 16:02:01.064780316 +0000
+++ app.js.1.8.0-dev.20151110   2015-11-12 16:05:07.933061708 +0000
@@ -2,10 +2,9 @@
     function A() {
     }
     A.prototype.doIt = function (x) {
-        var _this = this;
         x.forEach(function (v) {
             switch (v) {
-                case "test": console.log(_this);
+                case "test": console.log(this);
             }
         });
     };

This feels like a bug to me... but I might have missed something?

Thanks

message TS6029: Version 1.8.0-dev.20151110

{
  "compilerOptions": {
    "declaration": false,
    "jsx": "react",
    "module": "system",
    "noImplicitAny": true,
    "noLib": true,
    "outDir": "../dist/",
    "removeComments": false,
    "rootDir": ".",
    "sourceMap": true,
    "target": "es5"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions