Works with the AI tools you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+22 more

    TYPESCRIPT Engineering

    1

    Build and refactor production-ready TypeScript with strict type safety, runtime validation, and clean architecture.

    $5

    Secure checkout via Stripe

    30-day refund guarantee

    Converts to your local currency at checkout

    Security scanned
    TYPESCRIPT Engineering

    TYPESCRIPT Engineering

    Example session with this skill installed

    Refactor the following user profile fetching logic to be more type-safe. It currently uses 'any' for the API response and has no runtime validation.

    • Read your context and instructions
    • Compiled the typescript engineering

    I have refactored the profile fetching logic to remove any types and implement a safe boundary check. The solution introduces a dedicated UserProfile interface and a validation guard to ensure data integrity before it enters your application logic.

    Refactored Profile Service

    import { z } from 'zod';
    
    // 1. Define the domain model
    export interface UserProfile {
      id: string;
      email: string;
      displayName: string;
      role: 'admin' | 'user' | 'guest';
      createdAt: Date;
    }
    
    // 2. Define the runtime validation schema
    const UserProfileSchema = z.object({
      id: z.string().uuid(),
      email: z.string().email(),
      display_name: z.string().min(1),
      role: z.enum(['admin', 'user', 'guest']),
      created_at: z.string().datetime(),
    });
    
    /**
     * Fetches and validates a user profile from the API.
     * Replaces unsafe 'any' with a validated UserProfile type.
     */
    export async function fetchUserProfile(userId: string): Promise<UserProfile> {
      const response = await fetch(`/api/users/${userId}`);
      
      if (!response.ok) {
        throw new Error(`Failed to fetch user: ${response.statusText}`);
      }
    
      const rawData = await response.json();
      
      // 3. Validate at the boundary
      const result = UserProfileSchema.safeParse(rawData);
      
      if (!result.success) {
        console.error('Data validation failed:', result.error.format());
        throw new Error('Invalid user data received from server');
      }
    
      const { data } = result;
    
      // 4. Transform to internal domain model
      return {
        id: data.id,
        email: data.email,
        displayName: data.display_name,
        role: data.role,
        createdAt: new Date(data.created_at),
      };
    }
    

    Next steps

    1. Install zod via your package manager if not already present.
    2. Update the calling components to handle the new UserProfile return type.
    3. Add a unit test to verify the error handling when the API returns malformed JSON.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Struggling with any types, fragile interfaces, or runtime crashes in your TypeScript codebase? This skill enforces strict type safety and domain modeling to eliminate bugs before they hit production. It shifts the focus from writing loose scripts to engineering resilient systems across Node.js, React, and shared libraries.

    What it does

    • Strict Domain Modeling uses TypeScript types to represent business logic and prevent invalid states.
    • Boundary Validation implements runtime checks for external data to maintain internal type integrity.
    • Infrastructure Auditing reviews tsconfig.json, linting rules, and build tools to ensure environment consistency.
    • Refactoring Strategy decouples complex modules and replaces repetitive shapes with reusable, typed utilities.
    • Context-Aware Optimization tailors code for specific runtimes including CLI tools, browsers, and Next.js apps.

    How it works

    1. Context Analysis by inspecting your environment, package manager, and existing configuration files.
    2. System Audit to identify unsafe boundaries, broad any usage, or assertion-heavy logic.
    3. Strategic Refactor applying explicit return types and simplifying data flow.
    4. Verification via the local type checker and test runner to confirm correctness.

    Frameworks & tools

    Works with Node.js, React, Next.js, and standard TypeScript build chains. Compatible with various package managers and testing frameworks.

    Why this beats prompting it yourself

    Generic prompts often produce over-abstracted generics or "magic" types that are hard to maintain. This skill prioritizes explicit, readable patterns and runtime safety over clever type gymnastics.

    Use cases

    • Migrating a legacy JavaScript module to strict, documented TypeScript.
    • Debugging complex async race conditions or data transformations in Node.js.
    • Designing a shared component library with robust prop types and clear exports.
    • Fixing build-time errors caused by conflicting environment configurations.

    Known limitations

    Requires an existing TypeScript environment. Does not provide micro-optimizations for non-TypeScript runtime performance issues.

    How to use

    Skills on Agensi run inside your AI agent. Copy the prompt, paste it into your agent, and it connects to Agensi and installs this skill for you. If a payment is needed, your agent shows it to you first.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill passes our trust checks below.

    Security scanned

    Passed our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    30-day refund

    Not a fit? Get your money back

    Trust & safety

    Security scanned

    Verified clean today

    • Passed all security checks, Safe to install

    Listedtoday

    What's inside

    Frequently Asked Questions