-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
TypeScript Version: 2.7.0-dev.20171226
Code
class Test {
constructor() { }
public testPrototypeMethod() {
}
public testArrowMethod = () => { }
}
console.log(Test.prototype.testArrowMethod); // This should not compile
console.log(Test.prototype.testPrototypeMethod);
Expected behavior:
Test.prototype.testArrowMethod
should fail on compilation because it isn't on the classes prototype.
Actual behavior:
Test.prototype.testArrowMethod
does not fail on compilation but becomes undefined
at runtime.
Reason
The code above compiles into the following js:
var Test = /** @class */ (function () {
function Test() {
this.testArrowMethod = function () { };
}
Test.prototype.testPrototypeMethod = function () {
};
return Test;
}());
As can be seen, the arrow function is actually defined using this
instead of prototype
on instantiation. This is fine, but testArrowMethod
should not be able to be accessed from Test.prototype
SalathielGenese, zRosenthal and trotyl
Metadata
Metadata
Assignees
Labels
DeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScriptAn idea for TypeScript