The TypeCaster VSCode extension is designed to help developers quickly generate TypeScript interfaces for any object or API. It automates the process of creating interfaces for JavaScript objects or API responses, saving time and ensuring consistency across your codebase.
Features
Generate Interface from Object
Select any object or array of objects in your code, press Ctrl + Shift + B, and provide the name for the TypeScript interface. The generated interface will be copied to your clipboard.
Generate Interface from API
Configure a type-caster-config.json file to specify API details like domain, parameters, query, headers, etc. After configuring the file, you can select the API URL and press Ctrl + Shift + A to generate the TypeScript interface for that API URL.
Steps to Use
1. Generate Interface from Object or Array of Objects
Select the object or array of objects in your code.
Press Ctrl + Shift + B.
Enter the name for the generated TypeScript interface.
The interface will be automatically copied to your clipboard.
2. Generate Interface from API
Create the type-caster-config.json file:
Press Ctrl + Shift + Alt + B to create the configuration file.
Fill out the necessary data in the file such as:
domain: The base URL of your API.
parameters: Any required parameters for the API.
query: Query parameters for the API.
headers: Headers required for API requests (e.g., Authorization).
interfaceFilePath: Relative path where the generated interface should be saved (e.g., src/xyz).
Select the API URL in your code.
Press Ctrl + Shift + A to generate the TypeScript interface from the selected API URL.
3. Store Generate Interface from Object or Array of Objects in a specfic file
Create the type-caster-config.json file:
Press Ctrl + Shift + Alt + B to create the configuration file.
Fill out the necessary data in the file such as:
interfaceFilePath: Relative path where the generated interface should be saved (e.g., src/xyz).
interfaceFileName: Name of interface where interface should be saved (e.g., exampleInterface).
Press Ctrl + Shift + A to generate the TypeScript interface from the object or array of objects in a specific file.
Configuration File (type-caster-config.json) Example
The type-caster-config.json file should be placed in the .vscode folder of your project. Here's an example configuration: