Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Constructor Generator (TypeScript)New to Visual Studio Code? Get it now.
Constructor Generator (TypeScript)

Constructor Generator (TypeScript)

Harsh Taliwal

|
4 installs
| (0) | Free
Auto-generate constructor, fromJSON(), and getDefault() methods for TypeScript classes using AST analysis.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

TypeScript Constructor Generator

A production-grade VSCode extension that auto-generates constructor, static fromJSON(), and static getDefault() methods for TypeScript classes using AST analysis.

Features

  • Constructor Generation — Constructors with all properties as parameters
  • fromJSON() — Defensive JSON-to-class mapping with type validation
  • getDefault() — Returns an empty but valid instance with safe defaults

Usage

Code Action (Lightbulb)

  1. Place your cursor inside a TypeScript class
  2. Click the lightbulb icon (or press Ctrl+. / Cmd+.)
  3. Select "Generate Constructor"

Command Palette

  • Generate Constructor — All enabled generators

Configuration

Setting Default Description
tsConstructorGenerator.defaultValues See below Default values per type
tsConstructorGenerator.regionMarkerStart "// <cg-generated>" Start marker
tsConstructorGenerator.regionMarkerEnd "// </cg-generated>" End marker
tsConstructorGenerator.logLevel "info" Logging level
tsConstructorGenerator.generateConstructor true Include constructor
tsConstructorGenerator.generateFromJSON true Include fromJSON()
tsConstructorGenerator.generateGetDefault true Include getDefault()

Default Values

{
  "string": "\"\"",
  "number": "0",
  "boolean": "false",
  "array": "[]",
  "object": "null"
}

Type Support

Type Status Notes
string, number, boolean ✅ Full
string[], Array<T> ✅ Full
Optional (?) ✅ Full
Nullable (\| null) ✅ Full
Union with undefined ✅ Full
Enums ✅ Full Validates against known members
Nested classes ✅ Full Calls fromJSON()/getDefault()
Arrays of classes ✅ Full Maps via fromJSON()
Readonly properties ✅ Full
Default initializers ✅ Full Uses initializer value
Generics (Map, Set) ⚠️ Partial Known generics supported
Intersection types ⚠️ Partial Uses first constituent
Conditional types ❌ Treated as unknown
Mapped types ❌ Treated as unknown

License

MIT

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