Skip to content

Inline arrow function inside constructor misinterpreted as constructor args #29286

Closed
@samdenty

Description

@samdenty

TypeScript Version: 3.3.0-dev.201xxxxx

Search Terms:

'this' cannot be referenced in constructor arguments.

Code

class Test {
  constructor() {
    const func = (a = this) => 1
  }
}

Expected behavior:

Typescript shouldn't produce any errors, as this is not referenced inside the constructors parameters.

Actual behavior:

Typescript misinterprets the default parameter of the inline arrow function as a default parameter of the constructor (which is not allowed, and should produce an error).

Playground Link: here

Related Issues: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions