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
Answer 3 questions and Léa tailors the prompt to your situation.
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
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
Gemini Prompt for Generating SQL Queries
Gemini, Google's artificial intelligence model, excels at generating SQL queries through its deep understanding of data structures and database syntax. Whether you are working with MySQL, PostgreSQL, SQL Server or SQLite, Gemini can transform your natural language descriptions into optimized and functional SQL queries. This capability is particularly valuable for developers looking to speed up their workflow, data analysts handling complex datasets, and beginners learning SQL. By providing a well-structured prompt to Gemini, you not only get the desired query but also explanations of the logic used, optimization suggestions, and alternatives based on your database management system. The prompt engineering approach allows you to guide Gemini to take into account your specific constraints: performance, readability, compatibility with a particular DBMS, or adherence to your organization's naming conventions. Discover how to formulate your prompts to get the most out of Gemini in generating SQL queries.
Perplexity Prompt for Generating Python Code
Perplexity AI stands out from other AI assistants with its unique ability to combine real-time web search and code generation. When it comes to producing Python code, this advantage is significant: Perplexity can rely on the latest official documentation, current best practices, and up-to-date libraries to generate reliable and modern code. Unlike a classic LLM whose knowledge is frozen at a cutoff date, Perplexity verifies its sources in real time, drastically reducing the risk of obsolete code or deprecated functions. Whether you are a developer looking to speed up your workflow, a data scientist wanting to prototype quickly, or a beginner learning Python, a well-structured prompt turns Perplexity into a true development assistant. The key lies in the precision of your request: by specifying the technical context, constraints, and expected output format, you get production-ready code rather than a generic snippet. This guide offers optimized prompts to get the most out of Perplexity in your Python projects.
Prompt Claude for Generating Python Code
Claude, developed by Anthropic, is one of the most powerful AI assistants for generating Python code. With its deep understanding of programming paradigms, best practices, and popular libraries, Claude can produce clean, documented, and functional code in seconds. Whether you are a beginner developer looking to learn by example, or a professional wanting to speed up your workflow, knowing how to formulate an effective prompt makes all the difference between a generic snippet and production-ready code. The challenge is not simply to ask "write Python code", but to provide enough context — objective, constraints, style, error handling — so that Claude generates exactly what you need. A well-structured prompt yields code that follows PEP 8 conventions, includes type hints, handles edge cases, and integrates naturally into your existing project. In this guide, you will find an optimized main prompt as well as variants tailored to each expertise level to get the most out of Claude in your Python projects.
Gemini Prompt to Create a REST API
Creating a REST API is a fundamental skill in modern development, but it involves many architectural decisions: choice of framework, endpoint structure, authentication management, data validation, and documentation. Google Gemini excels at generating structured code and can guide you through each step of this process. Using a well-crafted prompt, you not only get the skeleton of your API but also best practices built in from the start: proper HTTP codes, centralized error handling, security middleware, and layered architecture. Whether you're building a microservice for a personal project or an enterprise API designed to handle thousands of requests, Gemini adapts its response to the requested complexity level. The main benefit is time savings during the scaffolding phase: instead of spending hours manually configuring each component, you get a solid, coherent foundation in seconds, which you can then customize to your specific business needs.