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
Analyze and Optimize Algorithmic Complexity
Analyze the Big O complexity of your algorithms and optimize them with appropriate data structures and more efficient algorithms.
Kubernetes Backup Strategy
Kubernetes Disaster Recovery Plan
Stable Diffusion Prompt to Generate a Database Schema
Stable Diffusion, primarily known for artistic image generation, can also be used creatively to produce visual representations of database schemas. By crafting precise prompts, you can generate entity-relationship diagrams, conceptual models, or architectural visualizations of data structures. This approach is particularly useful during brainstorming, technical documentation, or when presenting to non-technical stakeholders. Instead of manually drawing your schemas or using conventional tools like dbdiagram.io, Stable Diffusion allows you to create aesthetically pleasing and professional visual representations of your data models. The resulting outputs can serve as illustrations for documentation, technical blog posts, or training materials. It is important to note that Stable Diffusion generates images and not directly usable SQL code. The goal is therefore to produce clear, readable visuals representing the tables, columns, primary keys, relationships, and cardinalities of your database. With the right settings and a well-structured prompt, you will obtain schemas that are both informative and visually attractive.
Automate Your Git Commits with AI
This prompt analyzes a Git diff and automatically generates structured commit messages following project conventions, with atomic splitting if needed.