api-and-typing

Derive narrow UI types from generated API shapes using TypeScript utilities.

6.9k|262|Updated Mar 29, 2022
One-click install
npx skills add https://github.com/massCodeIO/massCode --skill api-and-typing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: api-and-typing
Source: https://github.com/massCodeIO/massCode/tree/main/.agents/skills/api-and-typing
Command: npx skills add https://github.com/massCodeIO/massCode --skill api-and-typing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The massCode UI often encounters the need to work with API types that originate from generated sources or DTOs. Duplicating or re-creating these shapes in renderer code leads to drift, maintenance burden, and inconsistent behavior. This skill emphasizes reusing existing generated types, and introduces guidelines for deriving narrow local types for UI models, while keeping API shapes intact.

Core Features & Use Cases

  • Reuse existing generated API types from renderer/services/api/generated or DTOs from src/main/api/dto, avoiding manual duplicates.
  • Create narrow, UI-only or derived display models using TypeScript utilities like Pick, Omit, Parameters, ReturnType, Awaited, and NonNullable.
  • Apply rules to determine when a local type is appropriate (UI-only models, form models, or derived views) and how to safely adapt API shapes.

Quick Start

Review a renderer component and replace any copied API shape with a narrow derived type based on the existing generated type.

Frequently Asked Questions about api-and-typing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I avoid duplicating API types in my UI components?

To avoid duplicating API types in UI components, reuse existing generated types or DTOs and derive narrow local view models using TypeScript utilities like Pick and Omit.

What's the best way to derive UI-only types from existing API DTOs?

The best way to derive UI-only types from existing API DTOs is to apply TypeScript utilities such as Pick, Omit, ReturnType, and Awaited to safely adapt the original API shapes for view models.

When should I create a local type instead of reusing an API type directly?

You should create a local type instead of reusing an API type directly when defining UI-only models, form models, or derived views that require narrowing the original API shape for specific renderer needs.

How does ReturnType or Awaited help with TypeScript API typing?

ReturnType and Awaited help with TypeScript API typing by extracting the resolved promise shapes from API functions, allowing you to derive accurate UI models without manually copying the underlying API shapes.

Can I use TypeScript Pick and Omit to adapt generated API shapes for forms?

Yes, you can use TypeScript Pick and Omit to adapt generated API shapes for forms by selecting only the required properties from the original DTOs to create safe, narrow form models.

Why do manually copied API shapes cause type drift in renderer code?

Manually copied API shapes cause type drift in renderer code because duplicating generated types or DTOs creates maintenance burdens and leads to inconsistent behavior when the original API shape changes.