GitHub Copilot Prompts

Expert prompts and techniques for pair programming with GitHub's AI coding assistant. Learn to generate code faster, debug smarter, and build better with Copilot.

Code GenerationPair ProgrammingAI Coding Assistant

Code Generation & Completion

Generate a React component that displays a list of users with filtering and sorting capabilities. Include TypeScript types and proper error handling.

Write a utility function that converts a JavaScript object to query parameters. Handle nested objects, arrays, and special characters. Include unit tests.

Create a custom React hook for managing form state with validation, error tracking, and submit handling. Include TypeScript interfaces.

Code Explanation & Documentation

Explain this algorithm step-by-step, including time and space complexity analysis. Suggest optimizations and edge cases.

Generate comprehensive JSDoc comments for this function, including parameter descriptions, return types, and usage examples.

Write detailed API documentation for this endpoint, including request/response examples, error codes, and authentication requirements.

Refactoring & Optimization

Refactor this code to use async/await instead of promise chains. Improve error handling with try-catch blocks.

Optimize this database query. Look for N+1 problems, missing indexes, and inefficient joins. Suggest index strategies.

Convert this class component to a functional React component using hooks. Migrate lifecycle methods to useEffect and extract custom hooks.

Debugging & Problem-Solving

I'm getting this error: [paste error]. Here's the relevant code: [paste code]. What's wrong and how do I fix it?

This function is returning unexpected values in these scenarios: [describe scenarios]. Debug it and suggest edge cases I should handle.

This test is failing with: [paste test output]. Help me understand why and write the correct assertion or fix the code.

Architecture & Design Patterns

Design the architecture for a [feature description]. What components, services, and data flows would you use? Suggest design patterns.

How should I apply the [design pattern name] to solve this problem: [describe problem]. Show code examples and explain the benefits.

Review this component structure for [specific purpose]. Suggest improvements for maintainability, testability, and performance.

Testing & Quality Assurance

Generate unit tests for this function. Cover happy path, edge cases, error scenarios, and boundary conditions using Jest/Vitest.

Write integration tests for this API endpoint. Test success, error handling, authentication, and data validation scenarios.

Create end-to-end tests for this user flow: [describe flow]. Use Cypress or Playwright to test across different browsers and viewport sizes.

Frequently Asked Questions

Related Prompts