Transpilation of optional chaining combined with type casting results in function call losing its context #44639
Labels
Bug
A bug in TypeScript
Fix Available
A PR has been opened for this issue
Rescheduled
This issue was previously scheduled to an earlier milestone
Milestone
Bug Report
🔎 Search Terms
optional chaining, type casting, transpiling
🕗 Version & Regression Information
When transpiling the optional chaining feature on a method class and combining it to a type casting, the generated code makes the function call loses its context (
this
).The same does not occur when transpiling the optional chaining feature without the type casting, or if you use type casting without transpiled optional chaining.
The behavior is the same since optional chaining was introduced to TypeScript since version 3.7.
⏯ Playground Link
Playground link with relevant code
💻 Code
Original TypeScript code:
Transpiles to:
🙂 Expected behavior
I believe that type casting should not make transpilation generates different code with different behavior for optional chaining or any other feature.
The text was updated successfully, but these errors were encountered: