Skip to content

this-function parameter can be renamed #9037

Closed

Description

function(this/**/: string, x: number) {
  return this.length;
}

Now try to rename or find all references at /**/.

Expected: Message "You cannot rename this element".

Actual: Rename just the parameter, nothing in the body. Find all references just finds one reference, the definition.

Probably this needs to be classified as ThisKeyword by the parser as long as that doesn't break anything else.

Activity

  1. sandersn commented on Jun 8, 2016

    @sandersn
    MemberAuthor

    Thanks to Wesley Wigham (@weswigham) for coming up with this one.

  2. DanielRosenwasser commented on Jun 14, 2016

    @DanielRosenwasser
    Member

    I dunno, I like the flexibility here - for instance, imagine I want to stop using this and want to start passing in an object explicitly? As long as this stays contained to the function and doesn't leak into other scopes that have their own this, I feel like this is fine.

  3. sandersn commented on Jun 14, 2016

    @sandersn
    MemberAuthor

    Unfortunately it would be a lot of work because this isn't treated like a normal identifier anywhere else. Notice that the current behaviour doesn't rename body thises. That's because those occurrences aren't linked to the parameter via a symbol, but ad-hoc code in checkThisExpression.

  4. weswigham commented on Jun 14, 2016

    @weswigham
    Member

    So, for consistency, we should probably just change the parameter to be a this-keyword, then if we actually want renaming capabilities, add a branch in find all references/rename where inputting a value-position this yields all similarly-scoped value-position thises.

    The other option being to leave it as a parameter and add special cases for parameters named 'this' in a bunch of places, which seems hackier to me, IMO.

  5. basarat commented on Jun 15, 2016

    @basarat
    Contributor

    imagine I want to stop using this and want to start passing in an object explicitly

    I end up adding this: {} and then fix the errors for this access and then after fixing I delete the this: {} annotation. Just a workflow that's worked for me personally ;) 🌹

  6. sandersn commented on Jun 17, 2016

    @sandersn
    MemberAuthor

    Sure, although #9198 is a lot bigger than this issue. The fix in #9171 just prevents rename for this identifiers, and the alternate approach of parsing a ThisKeyword as a parameter makes the possibility of renaming Just Working even less likely.

  7. ghost closed this as completedin #9270on Jun 24, 2016
  8. RyanCavanaugh commented on Jun 24, 2016

    @RyanCavanaugh
    Member

    Is this fixed?

  9. ghost added
    FixedA PR has been merged for this issue
    on Jun 24, 2016
  10. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions