Skip to content

'declare method' quick fix for adding a private method #37782

Description

@mjbvz

From microsoft/vscode#94118

TypeScript Version: 3.9.0-dev.20200330

Search terms

  • quick fix
  • declare method
  • private

Repro
For ts file:

index.ts

class Bar {
    bar() {
         this._baz(123)
    }
}
  1. Trigger quick fixes on _baz

Feature request:
#36249 added a quick fix for adding private properties. However there is no quick fix for adding a private method

Playground Link:

Related Issues:

Activity

  1. bpasero commented on Apr 10, 2020

    @bpasero

    I am the original one complaining about this: what I expect is NOT having 1 code action per visibility, but rather ONE code action (as today) with a tab-stop at the visibility that I can flip the various visibilities. I realise this may need support from VSCode too. Here is how it would work:

    • you trigger the code action
    • you get into a mode like snippets where certain places are stops you can cycle through with Tab key
    • each method or property has a tab stop where you can navigate to and once you are there, be able to select a modifier private, protected, public etc.
  2. a-tarasyuk commented on Apr 13, 2020

    @a-tarasyuk
    Contributor

    Daniel Rosenwasser (@DanielRosenwasser) Is there a way to have a sub action to handle tab-stop? Or need to generate all possible actions for various methods/properties and VSCode should resolve tab-stop? Do I need to close #37806, and revert #36249?

  3. DanielRosenwasser commented on Apr 13, 2020

    @DanielRosenwasser
    Member

    Could you explain what you mean by tab-stop? I feel like I have an idea, but I might be out of the loop on something.

  4. a-tarasyuk commented on Apr 13, 2020

    @a-tarasyuk
    Contributor

    Benjamin Pasero (@bpasero)

    Could you explain what you mean by tab-stop?

  5. mjbvz commented on Apr 13, 2020

    @mjbvz
    Author

    Tabstops are from VS Code's snippets: https://code.visualstudio.com/docs/editor/userdefinedsnippets#_tabstops

    There is no concept of tabstops in the TS Server api today since it only talks about text. I've opened #25207 which proposes adding the idea of snippets to typescript

  6. a-tarasyuk commented on Apr 14, 2020

    @a-tarasyuk
    Contributor

    Right now I see two ways for this issue

    1. Resolve this issue based on the original requirements
    2. Close feat(37782): 'declare method' quick fix for adding a private method #37806 revert Declare property quick fix should add private properties (or be configurable)  #36249 and add tab-stop for modifiers after TSServer: snippet completions #25207 will be implemented

    I feel like I have an idea

    Daniel Rosenwasser (@DanielRosenwasser) Maybe you have a better idea :)

  7. DanielRosenwasser commented on Apr 14, 2020

    @DanielRosenwasser
    Member

    Hah, I meant like "I might have an idea of what you mean by tab stops". I think the weird thing is that the rename location already allows you to make something #-private, but it's not clear whether we could make a conditional tabstop location for when the declaration isn't #-private

  8. bpasero commented on May 9, 2020

    @bpasero

    To demonstrate what I expect to happen, here is what Eclipse does:

    recording

    Notice how some tab-stops are linked, so renaming the method actually also renames the call!

    And what VSCode does:

    kap

    Paper cuts:

    • method is added above constructor???
    • no way to change anything after the method was inserted

    Can we reopen this or reconsider this?

  9. sandersn commented on May 11, 2020

    @sandersn
    Member

    Yeah, #37806 partially fixes this but doesn't address the full issue. I'll re-open that so we can unify the two fixes when post-codefix rename locations are available.

  10. asd34-45 commented on May 31, 2020

    @asd34-45
  11. asd34-45 commented on May 31, 2020

    @asd34-45
  12. asd34-45 commented on May 31, 2020

    @asd34-45
  13. arvind-nikam-halodoc commented on Mar 10, 2021

    @arvind-nikam-halodoc

    From microsoft/vscode#94118

    TypeScript Version: 3.9.0-dev.20200330

    Search terms

    • quick fix
    • declare method
    • private

    Repro
    For ts file:

    index.ts

    class Bar {
        bar() {
             this._baz(123)
        }
    }
    1. Trigger quick fixes on _baz

    Feature request:
    #36249 added a quick fix for adding private properties. However there is no quick fix for adding a private method

    Playground Link:

    Related Issues:

    It’s fixed i guess.
    Screenshot 2021-03-10 at 11 26 37 AM

  14. kamolovd commented on Aug 28, 2025

    @kamolovd

    This is my first investment in outsourcing, can I start with this? Matt Bierner (@mjbvz)

  15. tysoncung commented on Oct 7, 2025

    @tysoncung

    I noticed this issue. Have you tried checking the error logs or console output? That might help narrow down the root cause. I'd be happy to help investigate if you can share more details about your environment (OS, version, etc.).

  16. oppong07 commented on Jan 4, 2026

    @oppong07

    Hi! I’m going to implement the “declare method” quick fix and will open a PR from branch feat/37782-declare-method-quick-fix (fork: oppong07/TypeScript). I’ll add tests demonstrating the failing diagnostic and the expected result after applying the fix, and I will link this issue from the PR.
    If maintainers prefer this work be submitted to microsoft/typescript-go instead, please let me know.
    Branch: https://github.com/oppong07/TypeScript/tree/feat/37782-declare-method-quick-fix

  17. added a commit that references this issue on Feb 15, 2026
    33d7940
  18. tejash5489-lang commented on Aug 15, 2026

    @tejash5489-lang

    This looks like it's already resolved for the originally-reported case. #37806 (merged 2020-05-06) added the "Declare private method" / "Declare method" quick-fix actions in fixAddMissingMember.ts, and there's a fourslash test (codeFixAddMissingMember18_declarePrivateMethod.ts) covering exactly the repro from this issue:

    class A {
        constructor() {
            this._foo();
        }
    }

    Triggering the quick fix on _foo today produces private _foo() { throw new Error("Method not implemented."); }, and _baz(123) from the original repro would work the same way — TS infers private from the leading underscore via startsWithUnderscore().

    What's still open is the follow-up scope from later in this thread: a single linked quick-fix with a tab-stop to cycle between private/protected/public (and rename the call site in sync), which needs snippet/tabstop support in the language service — tracked separately in #25207 and still unimplemented. That's a materially bigger change than "add a declare-method codefix," so it's probably worth relabeling or splitting into its own issue so this one can close and new contributors don't duplicate the already-merged #37806 work (as looks like it might be about to happen).

  19. LeonxLJX commented on Sep 1, 2026

    @LeonxLJX

    I'd like to take this one — I'll follow up with a PR. (claiming via Stella (@LeonxLJX))

  20. LeonxLJX commented on Sep 1, 2026

    @LeonxLJX

    Hi! I'd like to add the 'declare method' quick fix. Plan: implement the code fix, add tests. May I be assigned?

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

    Good First IssueWell scoped, documented and has the green lightHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions