TS Mock Generator VS Code Extension
English | 简体中文
A powerful VS Code extension to generate Mock data from TypeScript interfaces, powered by AI.
Features
- Generate Mock Code: Generate realistic mock data using Faker.js based on your schemas or TypeScript types.
- Generate Mock JSON: Directly output mock JSON objects.
- Generate JSON Schema: Quickly create JSON schemas from your TypeScript interfaces. Now intelligently processes single-line comments (//) in your TypeScript code, converting them to JSDoc in-memory to ensure richer descriptions in the generated schema without modifying your source files.
- AI-Powered Generation: Leverage DeepSeek AI to intelligently generate mock code and data.
- Seamless Integration: Right-click context menus for easy access within your editor.
Demo
The following GIF demonstrates how to:
- Right-click on a TypeScript type.
- Generate Faker.js mock code (
TS -> Faker Mock
).
- Open the generated
.mock.js
file.
- Run the mock script (
Run MockJS
).
- View the output in the terminal.

Installation
- Open VS Code.
- Go to Extensions (Ctrl+Shift+X or Cmd+Shift+X).
- Search for "TS Mock Generator" .
- Click "Install".
Configuration
This extension requires a DeepSeek API Key to function. You can configure it in VS Code settings:
- Go to
File > Preferences > Settings
(or Code > Preferences > Settings
on macOS).
- Search for "TS Mock Generator".
- Enter your API Key in the
TS Mock Generator: Api Key
field.
- (Optional) Configure
TS Mock Generator: Api Url
, TS Mock Generator: Model
, and TS Mock Generator: Temperature
.
Usage
Generating Faker Mock Code from TypeScript
- Open a TypeScript file (
.ts
or .tsx
).
- Place your cursor inside or on a TypeScript interface or type definition.
- Right-click in the editor.
- Select
TS -> Faker Mock
.
- A new
.mock.js
file will be generated with Faker.js code.
Generating Mock JSON from TypeScript
- Open a TypeScript file (
.ts
or .tsx
).
- Place your cursor inside or on a TypeScript interface or type definition.
- Right-click in the editor.
- Select
TS -> JSON Mock
.
- A new
.mock.json
file will be generated with mock JSON data.
Running Generated Mock JS Files
- Open a generated
.mock.js
file.
- Right-click in the editor.
- Select
Run MockJS
.
- The output will be displayed in the VS Code output panel.
Troubleshooting
- "API Key is not configured": Ensure you have set your DeepSeek API Key in VS Code settings.
- "Request to AI service failed": Check your internet connection and API Key. The AI service might be temporarily unavailable.
- Context menu items not showing: Ensure you are in a
.ts
, .tsx
, .schema.json
, or .mock.js
file.
Development
Building and Asset Copying
To compile the TypeScript source code and copy necessary assets (like .txt
files for prompts) to the out
directory, use:
npm run compile
This command ensures that all required files are in place for the extension to run correctly.
For a seamless development experience, this project is configured to automatically format and fix linting issues on file save within VS Code. This is achieved via the .vscode/settings.json
file:
- Format on Save: Code will be automatically formatted using Prettier when you save a file.
- ESLint Auto Fix: ESLint issues that can be automatically fixed will be resolved upon saving.
Ensure you have the Prettier and ESLint VS Code extensions installed for this to work.
Contributing
Feel free to open issues or submit pull requests on GitHub.
License
This project is licensed under the MIT License - see the LICENSE file for details.