P
💻DeveloppementIntermediateAll AIs

Prompt to Implement Design Patterns in TypeScript

A prompt to generate complete, typed implementations of design patterns in TypeScript, with concrete examples, tests and functional variants.

Paste in your AI

Adapt this prompt

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

You are a senior software architect specializing in TypeScript and object-oriented design. Implement [PATTERN_NAME] in modern TypeScript (5.x or later) for [USE_CASE_DESCRIPTION].

Requirements

  1. Use strict TypeScript typing, including interfaces, generics, and utility types, to catch type errors at compile time.
  2. Provide a complete implementation with the required interfaces and types, clearly named classes, and a concrete example tied to the use case.
  3. Add comments explaining the role of each part of the pattern.
  4. Explain the benefits and limitations of the pattern in TypeScript compared with other languages.
  5. Include a simple unit test that verifies the expected behavior.
  6. Where appropriate, show a class-free functional variant using closures and higher-order functions.

Response format

  1. Explain the pattern in 3 to 4 sentences.
  2. Show a simplified UML diagram in ASCII.
  3. Provide the complete TypeScript code.
  4. Show a usage example.
  5. Include a unit test.
  6. Show a functional variant, if applicable.
  7. Explain when to use the pattern and when to avoid it.

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

Enter a pattern such as Singleton, Observer, Strategy, or Factory and describe where you need it. The prompt asks for a TypeScript implementation with strict typing and generics. It can also use conditional types, mapped types, or template literal types where they fit. A functional version gives you a second way to implement the pattern when appropriate. For Observer, a real-time notification system for an e-commerce dashboard gives the example a concrete job to do.

Use Cases

Learn design patterns with modern, typed TypeScript implementationsRefactor existing code by applying the right architectural patternPrepare technical interviews on software design in TypeScriptCreate a reusable pattern library for a development team

Expected Output

A complete TypeScript implementation of the requested design pattern including: a concise explanation, an ASCII diagram, typed source code with interfaces and generics, a contextual usage example, a unit test, and usage recommendations.

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.

1681
💻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.

640
💻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.

411
💻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.

474