Skip to content

Incorrect ES5 transpilation for 'this' usage in lambda as a constructor default parameterΒ #55637

Closed
@nevedaren

Description

@nevedaren

πŸ”Ž Search Terms

ES5, this alias

πŸ•— Version & Regression Information

  • This changed between versions 5.1.6 and 5.2.2

⏯ Playground Link

https://www.typescriptlang.org/play?target=1&ts=5.2.2#code/MYGwhgzhAEDqBOYAOSCm9oG8BQ1rAHsA7CAF3gFdhSD4AKXPaANzBAEsATMU1aAXmh0KJMADNUALiwBfAJQCAfNFIALdhAB0rDt17DREuQpxMWbLj1R1M8gNyMZ2RknjtWvc7qt1SATzQAVUMpaDAiPzlpACMCAhBUcKxGPHhUUgp4IhVKVAc8JydsIlQAdzhEFHQ6OQcgA

πŸ’» Code

// @target: es5
// @showEmit: true
class Wrapper {
  constructor(
    validate = (unsafe: {}) => this.validate(unsafe)) {
    validate({});
  }

  private validate(typeUnsafe: any): boolean {
    return true;
  }
}

new Wrapper();

Target: ES5

πŸ™ Actual behavior

Cannot read properties of undefined (reading 'validate') 

πŸ™‚ Expected behavior

No error (as with untranspiled version or with TS5.1.6)

Additional information about the issue

No response

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: JS EmitThe issue relates to the emission of JavaScriptFix AvailableA PR has been opened for this issueHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-repros

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions