I am looking for a tool or IDE that can help automatically refactor JavaScript or TypeScript function into a class.

It would be nice if it can take care of this keyword in a safe way but is not a requirement. I can also fix remaining issues manually afterwards.

The purpose I want to use it for, is easy migration/maintenance of a legacy code.



function MyService(dependency) {
    function privateMethod() {}

    function publicMethod() {
    return {


class MyService() {
    constructor(dependency) {}

    private privateMethod() {}

    public publicMethod() {
  • The only thing I have already found is something that can help me write it myself like jscodeshift
    – mpasko256
    Jun 12, 2022 at 12:42
  • Other tools and libraries I found to help me write it from scrach in a worst case scenario: vscode-refactor-by-js and ts-morph library.
    – mpasko256
    Jun 20, 2022 at 19:21

1 Answer 1


I googled your question and I found Visual Studio Code (you can see how to refactor here) - https://code.visualstudio.com/docs/editor/refactoring

Download link - https://code.visualstudio.com/

  • I use VSCode. Unfortunatelly it does not provide required refactoring method (to change a function into a class). Do you know any plugin supporting that?
    – mpasko256
    Jun 19, 2022 at 14:53
  • I googled and found this -code.visualstudio.com/docs/editor/…). Jun 20, 2022 at 15:03
  • @NinadKulkarmi The linka you provided navigates to the documentation of VSCode standard functionality. Unfortunately it does not meet my requirement. :(
    – mpasko256
    Jun 20, 2022 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.