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

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 :

  1. Utilise le typage strict de TypeScript (interfaces, generics, types utilitaires) pour garantir la sûreté du code à la compilation.
  2. 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
  3. Ajoute des commentaires expliquant le rôle de chaque élément du pattern.
  4. Montre les avantages et les limites de ce pattern dans le contexte TypeScript (par rapport à d'autres langages).
  5. Propose un test unitaire simple pour valider le comportement attendu.
  6. 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

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

  • 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

💻DeveloppementAdvancedAll AIs

Design a Robust Microservices Architecture

A complete prompt to design a professional microservices architecture covering DDD decomposition, inter-service communication, Kubernetes deployment, and observability.

0629
💻DeveloppementIntermediateAll AIs

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.

0272
💻DeveloppementAdvancedAll AIs

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.

0477
💻DeveloppementIntermediateAll AIs

Helm Chart for Application

Create a Helm chart

0430