Repository navigation
'declare method' quick fix for adding a private method #37782
Description
Activity
- addedGood First IssueWell scoped, documented and has the green lightWell scoped, documented and has the green lightHelp WantedYou can do thisYou can do thisSuggestionAn idea for TypeScriptAn idea for TypeScript
on Apr 3, 2020 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
Tabkey - 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,publicetc.
a-tarasyuk commented
on Apr 13, 2020 ContributorMore actionsDaniel 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 resolvetab-stop? Do I need to close #37806, and revert #36249?DanielRosenwasser commented
on Apr 13, 2020 MemberMore actionsCould 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.a-tarasyuk commented
on Apr 13, 2020 ContributorMore actionsCould you explain what you mean by tab-stop?
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
Reacted by Benjamin Paseroa-tarasyuk commented
on Apr 14, 2020 ContributorMore actionsRight now I see two ways for this issue
- Resolve this issue based on the original requirements
- 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-stopfor 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 :)
DanielRosenwasser commented
on Apr 14, 2020 MemberMore actionsHah, 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#-privateTo demonstrate what I expect to happen, here is what Eclipse does:
Notice how some tab-stops are linked, so renaming the method actually also renames the call!
And what VSCode does:
Paper cuts:
- method is added above constructor???
- no way to change anything after the method was inserted
Can we reopen this or reconsider this?
sandersn commented
on May 11, 2020 MemberMore actionsYeah, #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.
Reacted by Benjamin Pasero and Oleksandr TarasiukTypeScript Version: 3.9.0-dev.20200330
Search terms
- quick fix
- declare method
- private
Repro
For ts file:index.tsclass Bar { bar() { this._baz(123) } }
- 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 methodPlayground Link:
Related Issues:
NsdHSO commented
on Jul 23, 2024 More actionsDaniel Rosenwasser (@DanielRosenwasser) is it still open?
This is my first investment in outsourcing, can I start with this? Matt Bierner (@mjbvz)
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.).
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- added a commit that references this issue
on Feb 15, 2026 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
_footoday producesprivate _foo() { throw new Error("Method not implemented."); }, and_baz(123)from the original repro would work the same way — TS infersprivatefrom the leading underscore viastartsWithUnderscore().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).I'd like to take this one — I'll follow up with a PR. (claiming via Stella (@LeonxLJX))
Hi! I'd like to add the 'declare method' quick fix. Plan: implement the code fix, add tests. May I be assigned?



From microsoft/vscode#94118
TypeScript Version: 3.9.0-dev.20200330
Search terms
Repro
For ts file:
index.ts_bazFeature 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: