You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected behavior:
A warning or error on transpilation because this will be undefined.
OR
A warning or error on transpilation because we're passing a class instance method as a function parameter. Actual behavior:
Transpiles and then on run:
5
5
5
5
5
5
5
5
5
5
/home/seth/Desktop/test.js:8
O.prototype.getZ = function () { return this.n; };
^
TypeError: Cannot read property 'n' of undefined
at O.getZ (/home/seth/Desktop/test.js:8:49)
at indirect (/home/seth/Desktop/test.js:21:12)
at Object.<anonymous> (/home/seth/Desktop/test.js:28:13)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:148:18)
at node.js:405:3
The text was updated successfully, but these errors were encountered:
classO{constructor(privaten: string){}publicgetZ(this: O){returnthis.n;}}functionindirect(f: (this: void)=>string){returnf();}leto=newO('5');console.log(indirect(o.getZ));// Argument of type (this: O) => string is not assignable ...
Sadly automatic inferring of this didn't make it, because of negative performance implications :(. For further information see #6739
TypeScript Version: 2.1.0-dev.20160810
Code
Tried with
--target es5
and--target es6
Expected behavior:
A warning or error on transpilation because
this
will be undefined.OR
A warning or error on transpilation because we're passing a class instance method as a function parameter.
Actual behavior:
Transpiles and then on run:
The text was updated successfully, but these errors were encountered: