Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Guardz GeneratorNew to Visual Studio Code? Get it now.
Guardz Generator

Guardz Generator

Thien Nguyen

|
3 installs
| (0) | Free
VS Code extension for generating TypeScript type guards using guardz-generator
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Guardz Generator VS Code Extension

A VS Code extension that integrates with the guardz-generator package to automatically generate TypeScript type guards from your existing TypeScript interfaces and types.

Features

  • Generate Type Guards: Generate type guards for all types in the current TypeScript/JavaScript file
  • Generate from Selection: Select specific code and generate type guards for only those types
  • Context Menu Integration: Right-click in TypeScript/JavaScript files to access the generator
  • Command Palette Support: Use the command palette to access all features

Commands

guardz-generator.generateTypeGuards

Generates type guards for all types defined in the current file. The generated code will be opened in a new tab.

guardz-generator.generateFromSelection

Generates type guards for the selected code only. The generated code will replace the selection.

Usage

Method 1: Generate from entire file

  1. Open a TypeScript or JavaScript file
  2. Press Ctrl+Shift+P (or Cmd+Shift+P on Mac) to open the command palette
  3. Type "Generate Type Guards" and select the command
  4. The generated type guards will open in a new tab

Method 2: Generate from selection

  1. Select the TypeScript/JavaScript code you want to generate type guards for
  2. Right-click and select "Generate Type Guards from Selection"
  3. The generated type guards will replace your selection

Method 3: Command palette

  1. Press Ctrl+Shift+P (or Cmd+Shift+P on Mac)
  2. Type "Guardz Generator" to see all available commands
  3. Select the desired command

Example

Given this TypeScript interface:

interface User {
  id: number;
  name: string;
  email: string;
  isActive: boolean;
  profile?: {
    avatar: string;
    bio: string;
  };
}

The extension will generate type guards like:

import { isString, isNumber, isBoolean, isObject, isOptional } from 'guardz';

export const isUser = (value: unknown): value is User => {
  return isObject(value) &&
    isNumber((value as any).id) &&
    isString((value as any).name) &&
    isString((value as any).email) &&
    isBoolean((value as any).isActive) &&
    isOptional((value as any).profile, isUserProfile);
};

export const isUserProfile = (value: unknown): value is User['profile'] => {
  return isObject(value) &&
    isString((value as any).avatar) &&
    isString((value as any).bio);
};

Requirements

  • VS Code 1.102.0 or higher
  • TypeScript or JavaScript files

Installation

  1. Clone this repository
  2. Run pnpm install to install dependencies
  3. Run pnpm run compile to build the extension
  4. Press F5 in VS Code to launch the extension in a new Extension Development Host window

Development

  • pnpm run compile - Compile the TypeScript code
  • pnpm run watch - Watch for changes and recompile
  • pnpm run test - Run tests

License

MIT

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