mcpField
T
typescript-advanced-types

typescript-advanced-types

github.com/flpbaladaDevelopment835 installsUpdated 1d ago
Repository

About typescript-advanced-types

A skill for TypeScript developers using advanced types while keeping code readable. It covers generics, conditional types, type guards, and optional context files with examples.

Key features

  1. 01Uses unknown for untrusted input
  2. 02Applies generics and conditional types
  3. 03Transforms object properties with mapped types
  4. 04Narrows types with type guards
  5. 05Tests reusable type utilities

Use cases

  1. 01Typing reusable logic across related types
  2. 02Modeling data with multiple variants
  3. 03Validating external input and narrowing types
  4. 04Building and testing type utilities

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/flpbalada/fb-skills --skill typescript-advanced-types

After installing, type/typescript-advanced-typesin Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

context/
core-examples.md
patterns.md
techniques.md

Details

From the project README

TypeScript Advanced Types

Goal

Use advanced types to improve safety without making code unreadable. Prefer simple types until complexity pays for itself.

Rules

  • Use unknown instead of any when input is not trusted.
  • Let TypeScript infer simple types.
  • Add generics only when a type must connect multiple positions.
  • Prefer unions and discriminated unions for variants.
  • Prefer interface for object shapes.
  • Use type for unions, conditionals, mapped types, and aliases.
  • Avoid deeply nested conditional or recursive types.
  • Add type tests for reusable utilities when the project supports them.

Core Tools

  • Generics: reuse logic across related types.
  • Conditional types: choose a type from a type condition.
  • Mapped types: transform object properties.
  • Template literal types: constrain string patterns.
  • Utility types: use Pick, Omit, Partial, Required, Readonly, Record.
  • infer: extract inner types from arrays, promises, functions, or objects.
  • Type guards: narrow unknown at runtime.
  • Assertion functions: throw when runtime validation fails.
  • Branded types: distinguish validated strings or IDs.

Generic Rule

If a type parameter appears only once, it is probably unnecessary.

Useful Patterns

type StrictOmit<T, K extends keyof T> = Omit<T, K>;
type ElementType<T> = T extends (infer U)[] ? U : never;
type UserId = string & { readonly __brand: "UserId" };
type User = z.infer<typeof userSchema>;

Avoid

  • any as a shortcut.
  • Type assertions when a guard is possible.
  • Overly clever types that hide intent.
  • Unbounded generic parameters.
  • Duplicating types already available from schema or API definitions.
  • Recursive types that slow the compiler.

Progressive Disclosure

This skill provides detailed examples through context files. Load them when needed:

Context FileWhen to Load
context/core-examples.mdNeed generics, conditionals, mapped types examples
context/patterns.mdImplementing real-world patterns like EventEmitter, API client, or Builder
context/techniques.mdType inference, guards, assertions, and testing

References

Output

  • Type approach.
  • Simplest type shape.
  • Generic constraints if needed.
  • Runtime validation boundary when input is unknown.

Comments

Markdown supported