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
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
- Use strict TypeScript typing, including interfaces, generics, and utility types, to catch type errors at compile time.
- Provide a complete implementation with the required interfaces and types, clearly named classes, and a concrete example tied to the use case.
- Add comments explaining the role of each part of the pattern.
- Explain the benefits and limitations of the pattern in TypeScript compared with other languages.
- Include a simple unit test that verifies the expected behavior.
- Where appropriate, show a class-free functional variant using closures and higher-order functions.
Response format
- Explain the pattern in 3 to 4 sentences.
- Show a simplified UML diagram in ASCII.
- Provide the complete TypeScript code.
- Show a usage example.
- Include a unit test.
- Show a functional variant, if applicable.
- 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
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 OptimizerComments
Be the first to comment on this prompt.
Glossary Terms
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Go further
Improve this prompt with the Optimizer
Analyze the prompt, strengthen the context and get a more precise version.
Prompt Engineering
Cross-model principles for writing more reliable prompts.
AI prompts for web developers
Code review and debugging, keeping API keys and secrets out of the prompt.
Security, GDPR & Business Plans
ChatGPT Business, Claude Team, Gemini Workspace and Mistral Vibe compared from vendor sources: training, EU hosting and a GDPR checklist.
Similar Prompts
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.
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.
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.
Generate Storybook Stories for UI Components
Generate Storybook stories for a UI component, with visual variants, interactive controls, interaction tests, and MDX documentation.