Use the LWC TypeScript MCP Tool (Beta)
The convert_lwc_to_typescript tool adds type safety while preserving existing functionality, ensuring that your JavaScript code is valid and the component structure is organized. The tool also runs the conversion with LWC-Specific considerations.
Before you use this tool on your LWC project, make sure you:
MCP Tools for LWC is a pilot or beta service that is subject to the Beta Services Terms at Agreements - Salesforce.com or a written Unified Pilot Agreement if executed by Customer, and applicable terms in the Product Terms Directory. Use of this pilot or beta service is at the Customer's sole discretion.
Here are some possible prompts that invoke the LWC TypeScript tool.
Ask about converting your LWC code to TypeScript.
- Convert JavaScript files in force-app/main/default/lwc to TypeScript with strict typing.
- Convert myComponent to TypeScript, infer @api/@track types, and do a dry run first.
- Migrate these files to TypeScript and update imports: force-app/main/default/lwc/myComponent/myComponent.js, force-app/main/default/lwc/otherComponent/otherComponent.js; include a summary report.
The tool follows these conversion guidelines.
- Renames JavaScript files without a TypeScript version to
.ts - Adds type annotations for all variables and parameters
- Creates Interfaces for complex objects
- Generates JSDoc comments for
@apimembers if they're missing - Generates
.d.tsfile with@apimembers only - Preserves JSDoc comments in type definitions
The LWC compiler doesn't compile TypeScript files. Before you can deploy your TypeScript files, compile your TypeScript code to Javascript.
See Also