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.
Tu es un architecte logiciel senior spécialisé en TypeScript et en conception orientée objet. Implémente le design pattern [NOM_DU_PATTERN] en TypeScript moderne (5.x+) pour le cas d'usage suivant : [DESCRIPTION_DU_CAS_USAGE].
Exigences :
- Utilise le typage strict de TypeScript (interfaces, generics, types utilitaires) pour garantir la sûreté du code à la compilation.
- Fournis une implémentation complète avec :
- Les interfaces et types nécessaires
- La ou les classes du pattern avec des noms explicites
- Un exemple d'utilisation concret lié au cas d'usage décrit
- Ajoute des commentaires expliquant le rôle de chaque élément du pattern.
- Montre les avantages et les limites de ce pattern dans le contexte TypeScript (par rapport à d'autres langages).
- Propose un test unitaire simple pour valider le comportement attendu.
- Si pertinent, montre une variante fonctionnelle (sans classe) exploitant les closures et les higher-order functions de TypeScript.
Format de réponse :
- Section 1 : Explication du pattern en 3-4 phrases
- Section 2 : Diagramme UML simplifié en ASCII
- Section 3 : Code TypeScript complet
- Section 4 : Exemple d'utilisation
- Section 5 : Test unitaire
- Section 6 : Variante fonctionnelle (si applicable)
- Section 7 : Quand utiliser et quand éviter ce pattern
Personalize this prompt with Léa
Léa rewrites this prompt for your job and your exact goal — 3 quick questions.
Why this prompt works
<p>This prompt transforms AI into a TypeScript-specialized software architect to provide you with rigorous design pattern implementations. By specifying the <strong>pattern name</strong> (Singleton, Observer, Strategy, Factory, etc.) and your <strong>concrete use case</strong>, you get code directly applicable to your project rather than generic examples.</p><p>The strength of this prompt lies in its requirement for <strong>strict typing</strong> and <strong>TypeScript generics</strong>. Unlike classic implementations often ported from Java or C#, the generated code fully leverages TypeScript's type system: conditional types, mapped types, template literal types. The functional variant request also allows exploring more idiomatic TypeScript approaches.</p><p>For better results, be specific about your use case. For example, instead of simply requesting the Observer pattern, describe <strong>"a real-time notification system for an e-commerce dashboard"</strong>. The richer the context, the more relevant and ready-to-use the implementation will be in your codebase.</p>
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
- LéaAI
Pour un résultat exploitable, précisez dans `[DESCRIPTION_DU_CAS_USAGE]` le contexte concret (framework, contraintes, versions) et ajoutez une exigence de gestion des cas limites (erreurs, nullabilité). Si le pattern est structurel, demandez un exemple réel (logging, cache, validation) plutôt qu’un cas générique.
📬 Get new prompts every week
Join our newsletter and never miss a prompt.
Go further
Similar Prompts
Design a Robust Microservices Architecture
A complete prompt to design a professional microservices architecture covering DDD decomposition, inter-service communication, Kubernetes deployment, and observability.
GitHub Copilot Prompt for Documenting Code
Code documentation is often neglected by developers, yet it is a fundamental pillar of software maintainability. GitHub Copilot, integrated directly into your code editor, turns this time-consuming task into a smooth and nearly instant process. By analyzing your code context — function names, parameters, return types, internal logic — Copilot generates relevant comments, docstrings, and technical documentation in seconds. Whether you are working on a REST API, an open-source library, or a corporate project, a well-crafted prompt enables Copilot to produce structured, consistent documentation that adheres to your language's conventions (JSDoc, Python docstrings, Javadoc, etc.). The challenge is not simply to describe what the code does, but to capture the why — architectural decisions, edge cases, business constraints. With the right prompts, Copilot becomes a true technical co-writer capable of significantly accelerating your documentation workflow without sacrificing quality.
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.
Helm Chart for Application
Create a Helm chart