P
💻DeveloppementAdvancedAll AIs

Master Advanced TypeScript Types with AI

A prompt to generate advanced TypeScript types (generics, mapped types, conditional types) with documentation and built-in type tests.

Paste in your AI

Adapt this prompt

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

You are a TypeScript expert specializing in the advanced type system. I'm working on [project description] and I need to create robust types for [specific use case].

Technical context:

  • TypeScript version: [TS version]
  • Strict mode: enabled
  • Existing types I want to improve or extend: [existing types]

Your mission:

  1. Analyze my needs and propose advanced types using the appropriate features among: constrained generics, mapped types, conditional types, template literal types, infer, satisfies, const assertions.
  2. For each type you create, add a JSDoc comment explaining its role and an example of use.
  3. Create reusable utility types where relevant (DeepPartial, StrictOmit, etc.).
  4. Add test types with Expect<Equal<...>> to verify that the types behave correctly.
  5. Flag common pitfalls (variance, union distribution, excessive complexity) and suggest alternatives if a type becomes unreadable.

Response format:

  • Commented TypeScript code, organized by responsibility
  • A separate "Utility types" section if applicable
  • A "Type tests" section at the end of the file
  • Explanations in English in the comments

Personalize this prompt with Léa · AI assistant

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

Why this prompt works

This prompt is designed to fully leverage TypeScript's type system, one of the most powerful among mainstream languages. By providing your project context and specific use cases, the AI can generate custom types that go well beyond basic interfaces. The variables to customize are essential: describe your project precisely (REST API, state management, ORM...) and the use case (type API responses, create a typed builder pattern, validate configurations). The more specific you are, the more relevant and directly usable the generated types will be. Best practices for use: • Paste your existing types in [EXISTING_TYPES] so the AI extends them intelligently rather than starting from scratch. • Request iterations if a type is too complex — readability trumps elegance. • Use the generated type tests to validate behavior before integrating into your codebase.

Use Cases

Type REST API responses with generics and discriminated unionsCreate a type-safe configuration system with autocompletion for a framework or libraryImplement advanced patterns like builder pattern or state machine fully typed

Expected Output

TypeScript code containing advanced types documented with JSDoc, reusable utility types, and a type test suite verifying expected behavior. Everything is organized by responsibility and commented.

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

Be the first to comment on this prompt.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

💻DeveloppementIntermediateClaude

Task brief for Claude Code: frame a feature end to end

Brief template to delegate a complete feature to Claude Code: goal, starting point, constraints, definition of done, working rules and recap format.

1671
💻DeveloppementIntermediateClaude

Write a project's CLAUDE.md: the brief Claude Code reads at every session

Turns your project description into a dense CLAUDE.md: commands, structure, conventions, pitfalls, off-limits areas and situations where the agent must ask before acting.

632
💻DeveloppementAdvancedAll AIs

Design a Secure Webhook API

Design a webhook API with event subscriptions, signed deliveries, retry limits, and a delivery log your support team can inspect.

408
💻DeveloppementIntermediateAll AIs

Generate Storybook Stories for UI Components

Generate Storybook stories for a UI component, with visual variants, interactive controls, interaction tests, and MDX documentation.

468