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

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

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

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

💻DeveloppementIntermediateAll AIs

Integration Testing for REST APIs

Test API endpoints under real-world conditions

0103
💻DeveloppementIntermediateAll AIs

Implement secrets management

Secure credentials management

097
💻DeveloppementBeginnerAll AIs

Convert CSS to Tailwind

Migrate styling to Tailwind

086
💻DeveloppementAdvancedAll AIs

Design an event-driven system

Architect event-driven systems

0109