dry-types

Derive TypeScript types from base definitions using extends, Pick, Partial, and keyof.

Updated Jul 17, 2017
One-click install
npx skills add https://github.com/luyi985/lyi-bash --skill dry-types
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dry-types
Source: https://github.com/luyi985/lyi-bash/tree/main/ai/skills/dry-types
Command: npx skills add https://github.com/luyi985/lyi-bash --skill dry-types

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Duplicated type definitions lead to inconsistencies, maintenance burden, and bugs. This skill shows how to derive types from a single source of truth using TypeScript's type operations and generics, so types stay in sync automatically.

Core Features & Use Cases

  • Derive types from base definitions using extends, Pick, Partial, and keyof to create related variants (e.g., optional versions, subsets, or derived types).
  • Promote base + extensions, input/output types, and mapped/utility types to reduce drift across interfaces and data structures.
  • Real-world scenarios include keeping User, Form, and API response types aligned without duplicating fields.

Quick Start

Create or identify a base interface and derive a new type with Partial and Pick to produce an update model.

Frequently Asked Questions about dry-types

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

FAQPage Schema
How do I derive TypeScript types from a base interface to prevent type drift?

Derive TypeScript types from a base interface by applying utility types like Pick, Partial, and keyof to create related variants, ensuring multiple types share fields and stay automatically synced to a single source of truth.

What is the best way to keep API response and form types aligned in TypeScript?

The best way to keep API response and form types aligned is to define a single base interface and derive update or subset models using TypeScript type operations like Partial and Pick, eliminating duplicated definitions that cause inconsistencies.

Do I need to know TypeScript generics to use utility types like keyof and extends?

Yes, you need prerequisite knowledge of TypeScript utility types and generics to reliably apply operations like extends, keyof, and Pick for deriving related types and promoting base definitions with extensions.

When should I use Partial versus Pick for deriving TypeScript types?

Use Partial to create optional versions of base fields for update models, and use Pick to create subsets by extracting specific fields, reducing drift across interfaces while keeping derived types synced to the original definition.

Why does defining duplicate TypeScript interfaces for input and output cause bugs?

Defining duplicate TypeScript interfaces causes bugs because manual updates lead to inconsistencies and drift when fields change; deriving types from a single source of truth using type operations prevents these maintenance burdens.