franky47/dotfiles/typescript-advanced-types

Claude Code and agent skill by franky47/dotfiles

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Master TypeScript's advanced type system including generics, conditional types, mapped types, template literals, and utility types for building type-safe applications. Use when implementing complex type logic, creating reusable type utilities, or ensuring compile-time type safety in TypeScript projects.

Install

npx vskill@latest install franky47/dotfiles/typescript-advanced-types

SKILL.md

The same SKILL.md was published earlier as franky47/dotfiles/typescript-advanced-types.

TypeScript Advanced Types

Comprehensive guidance for mastering TypeScript's advanced type system including generics, conditional types, mapped types, template literal types, and utility types for building robust, type-safe applications.

When to Use This Skill

  • Building type-safe libraries or frameworks
  • Creating reusable generic components
  • Implementing complex type inference logic
  • Designing type-safe API clients
  • Building form validation systems
  • Creating strongly-typed configuration objects
  • Implementing type-safe state management
  • Migrating JavaScript codebases to TypeScript

Core Concepts

1. Generics

Purpose: Create reusable, type-flexible components while maintaining type safety.

Basic Generic Function:

function identity<T>(value: T): T { return value; }

const num = identity<number>(42); const str = identity<string>("hello"); const auto = identity(true); // Type inferred: boolean

Note: using a single letter for trivial generics can be OK, but prefer giving generic arguments a relevant short name instead.

Generic Constraints:

type HasLength = { length: number; }

function logLength<T extends HasLength>(item: T): T { console.log(item.length); return item; }

Multiple Type Parameters:

function merge<T, U>(obj1: T, obj2: U): T & U { return { ...obj1, ...obj2 }; }

2. Conditional Types

type IsString<T> = T extends string ? true : false; type ReturnType<Fn> = Fn extends (...args: any[]) => infer Return ? Return : never; type ToArray<Item> = Item extends any ? Item[] : never;

3. Mapped Types

type Readonly<T> = { readonly [P in keyof T]: T[P] }; type Partial<T> = { [P in keyof T]?: T[P] }; type Getters<T> = { [K in keyof T as get${Capitalize<string & K>}]: () => T[K] }; type PickByType<T, U> = { [K in keyof T as T[K] extends U ? K : never]: T[K] };

4. Template Literal Types

type EventName = "click" | "focus" | "blur"; type EventHandler = on${Capitalize<EventName>};

5. Utility Types

Partial<T>, Required<T>, Readonly<T>, Pick<T, K>, Omit<T, K>, Exclude<T, U>, Extract<T, U>, NonNullable<T>, Record<K, T>

Advanced Patterns

  • Type-Safe Event Emitter
  • Type-Safe API Client
  • Builder Pattern with Type Safety
  • Deep Readonly/Partial
  • Type-Safe Form Validation
  • Discriminated Unions

Type Inference Techniques

  • infer keyword for extracting types
  • Type guards with value is Type
  • Assertion functions with asserts value is Type

Strict mode

In tsconfig.json, strict mode should always be enabled. The following flags should also be on:

  • "noFallthroughCasesInSwitch": true
  • "noUncheckedIndexedAccess": true
  • "noPropertyAccessFromIndexSignature": true

Don't type-cast catch (err: unknown) {}, err is already unknown in strict mode: catch (err) {}.

Best Practices

  1. Use unknown over any
  2. Use type over interface for object shapes
  3. Use interface for declaration-mergeable types (extensible in userland)
  4. Leverage type inference
  5. Create helper types for reuse
  6. Use const assertions
  7. Avoid type assertions — use type guards
  8. Use tsconfig strict settings eagerly
  9. Document complex types
  10. Use strict mode
  11. Test your types

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/franky47/dotfiles/typescript-advanced-types/badge)](https://verified-skill.com/skills/franky47/dotfiles/typescript-advanced-types)

Something wrong with this skill or its page? Tell us.