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
I expect that the code generated for super.bar() and (super.bar as any)() behave the same - this code should console.log(2) twice.
Actual behavior:
The code logs 2, and then undefined.
The underlying issue is that super.bar() and (super.bar as any)() compile to different code. the former compiles to _super.prototype.bar.call(this);, but the as any changes the compilation to _super.prototype.bar();, and so super.bar is called with the wrong this when the cast is in place.
I was generally under the impression that code generation should be the same whether or not casts were present in the code, so I found this a bit surprising. that said, it was easy to change my code to avoid this pitfall.
The text was updated successfully, but these errors were encountered:
TypeScript Version: 2.6.1
Code
Expected behavior:
I expect that the code generated for
super.bar()
and(super.bar as any)()
behave the same - this code should console.log(2) twice.Actual behavior:
The code logs 2, and then undefined.
The underlying issue is that
super.bar()
and(super.bar as any)()
compile to different code. the former compiles to_super.prototype.bar.call(this);
, but theas any
changes the compilation to_super.prototype.bar();
, and sosuper.bar
is called with the wrongthis
when the cast is in place.I was generally under the impression that code generation should be the same whether or not casts were present in the code, so I found this a bit surprising. that said, it was easy to change my code to avoid this pitfall.
The text was updated successfully, but these errors were encountered: