Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>with-functions-generatorNew to Visual Studio Code? Get it now.
with-functions-generator

with-functions-generator

Tran Duy An Khuong

|
28 installs
| (0) | Free
Generate with-functions for class
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

with-functions-generator

https://user-images.githubusercontent.com/10008800/175754932-80503d62-77b5-4e90-8039-8075e30e83ea.mp4

What this extension does

Create with-functions for a class, usually used for mocking class for unit test.

Original

class MyModelMock {
  private id = 1;
  private name = "Michael Jackson";
  private email = "test@gmail.com";
}

After

  1. Without type (Generate withFunctions command)
class MyModelMock {
  private id = 1;
  private name = "Michael Jackson";
  private email = "test@gmail.com";

  public withId(id) {
    this.id = id;
    return this;
  }

  public withName(name) {
    this.name = name;
    return this;
  }

  public withEmail(email) {
    this.email = email;
    return this;
  }
}
  1. With type (Generate withFunctions with types command)
class MyModelMock {
  private id = 1;
  private name = "Michael Jackson";
  private email = "test@gmail.com";

  public withId(id: PleaseRenameThisType['id']) {
    this.id = id;
    return this;
  }

  public withName(name: PleaseRenameThisType['name']) {
    this.name = name;
    return this;
  }

  public withEmail(email: PleaseRenameThisType['email']) {
    this.email = email;
    return this;
  }
}

How to use

  • Hold Alt and double-click each private variable to multi-select them.
  • Press Ctrl + Shift + P to open the command palette.
  • Type Generate withFunctions or Generate withFunctions with type and press Enter.

Contribution

Please refer CONTRIBUTION.md

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft