Automatically refactor JavaScript or TypeScript functions to use object parameters instead of multiple positional parameters, improving readability and maintainability.
- Automatic Refactoring: Converts function signature and all call sites across your workspace
- Smart Detection: Identifies confirmed safe conversions and asks about uncertain cases
- Preview Mode: Optional preview dialogs to review each change before applying
- Workspace-Wide: Scans and updates all matching files in your project
- Type-Safe: Preserves TypeScript types, optional parameters, and function return types
Preview walkthrough is optional.
- Place your cursor inside a function definition.
- Right-click and select "Objectify Params" or use the Command Palette. You can assign your own hot-key.
- Review any uncertain conversions in interactive dialogs. In every dialog the cancel button will remove all changes.
- The extension updates both the function signature and all call sites.
function createUser(name: string, age = 22) {
return { name, age };
}
createUser("Alice", 30);
createUser("Bob");function createUser($: { name: string; age?: number }) {
let { name, age = 22 } = $;
return { name, age };
}
createUser({ name:"Alice", age:30 });
createUser({ name:"Bob" });Access settings via File > Preferences > Settings and search for "Objectify Params":
- Type:
boolean - Default:
true - Show preview dialog for every call conversion (including confirmed safe calls)
- Type:
number - Default:
1000 - Range: 0-5000ms
- Duration in ms to show preview highlights. Set to
0to show only the dialog without delay
- Type:
string - Default:
$par$ - Provide a variable name for a single object parameter in the signature. The extension inserts
let { ... } = $par$;as the first statement inside the function body. If this field is blank then the object is destructured inline in the parameter list.
- Type:
boolean - Default:
true - When disabled, any extracted TypeScript types are replaced with
any, dropping type information for both the incoming object and the destructured properties.
- Type:
string - Default:
"**/node_modules/**" - Space-separated glob patterns to exclude
- Priority over includes
- Type:
string - Default:
"**/*.ts **/*.js" - Space-separated glob patterns of files to scan
These demonstrate how objectVariable (inline vs $par$) and preserveTypes (original types vs any) change the generated code. All examples start from the same simple function:
function welcome(name: string, age = 21) {
console.log(name, age);
}
welcome("Ava", 33);
welcome("Ben");- Signature keeps
$par$and the body destructures on the first line while preserving full TypeScript types.
function welcome($par$: { name: string; age?: number }) {
let { name, age = 21 } = $par$;
console.log(name, age);
}
welcome({ name: "Ava", age: 33 });
welcome({ name: "Ben" });- Parameters destructure inline in the signature, still keeping the extracted types.
function welcome({ name, age = 21 }: { name: string; age?: number }) {
console.log(name, age);
}
welcome({ name: "Ava", age: 33 });
welcome({ name: "Ben" });- Keeps
$par$but drops explicit property types, replacing the object annotation withanyfor quicker editing.
function welcome($par$: any) {
let { name, age = 21 } = $par$;
console.log(name, age);
}
welcome({ name: "Ava", age: 33 });
welcome({ name: "Ben" });- Inline destructuring combined with a simple
anyannotation on the entire parameter.
function welcome({ name, age = 21 }: any) {
console.log(name, age);
}
welcome({ name: "Ava", age: 33 });
welcome({ name: "Ben" });- Scanning: Searches your workspace for all references to the function
- Classification: Categorizes calls as:
- Confirmed: Safe to convert automatically
- Fuzzy: Requires user review (name collisions, argument mismatches, etc.)
- Incompatible: Cannot convert (call/apply/bind, spread arguments)
- Interactive Review: Shows dialogs for fuzzy cases where you choose Convert or Skip
- Application: Updates function signature and all approved call sites
- Verification: Highlights the updated function signature
- TypeScript (
.ts,.tsx,.mts,.cts) - JavaScript (
.js,.jsx,.mjs,.cjs) - Vue (
.vue) - Svelte (
.svelte)
- VS Code 1.50.0 or higher
- Works with both JavaScript and TypeScript projects
- Cannot convert functions called with
.call(),.apply(), or.bind() - Cannot convert functions called with spread arguments (
...args) - Rest parameters must use tuple syntax for type preservation
- Show Previews: Enable
showPreviewsto review every conversion step-by-step - Fast Mode: Set
highlightDelayto0for instant dialogs without preview delays - Selective Scanning: Adjust
includepatterns to limit scope for faster processing - Undo Support: All changes are applied through VS Code's undo system
MIT
- Visual Studio Marketplace
- GitHub Repository
- Issues and pull requests welcome
Mark Hahn (eridien)
