8000 Enhancement: scope-manager should collect definition and references of `this` · Issue #10609 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content
Enhancement: scope-manager should collect definition and references of this #10609
Open
@Josh-Cena

Description

@Josh-Cena

Before You File a Proposal Please Confirm You Have Done The Following...

Relevant Package

scope-manager

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

While working on #1991, we discovered that there's no way currently to detect if a method signature uses this. The reason is that this:

interface X {
  foo(): this;
}

Is not transformable to this:

interface X {
  foo: () => this;
}

While I don't exactly understand the assignability differences and what this means in each case, my understanding is we want to look for method signatures that reference this, but this has to refer to the type bound by the method, so we still keep the autofix for:

interface X {
  foo(): (this: Y) => this;
}

Therefore, the best way is to track this in the scope manager, similar to how we automatically inject arguments for FunctionScope. In fact, for the code above, we already track this as a normal variable.

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    blocked by external APIBlocked by a tool we depend on exposing an API, such as TypeScript's Type Relationship APIenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0