Categories
TypeScript API Refactor Review Checklist
Prioritized, merge-focused checklist that finds type/runtime regressions, missing tests, migration gaps, and CI verification steps
for TypeScript API refactor PRs.
What You'll Get
-
Prioritized inline review comments with exact file/line hints and minimal code/type fixes.
-
Concrete, minimal unified-diff patches for critical fixes or compatibility shims.
-
A short list of missing or weakened tests with exact test names, assertions, file locations, and reproduction steps.
-
A migration plan snippet for downstream consumers listing breaking changes, shims, deprecations, and before→after
examples.
-
Exact CI and local commands to reproduce failures and verification steps, plus a 1‑paragraph risk summary with numeric risk
score and top 3 blockers.
How to Use
-
1Provide PR title, PR description, full unified file diff (git patch format), test/CI logs, package.json and tsconfig.json,
and list of public API files/known consumers when invoking the prompt.
-
2If any required input is missing, stop and request the missing artifact(s) before running the review.
-
3Run iteratively: apply critical MUST FIX patches, re-run tsc and failing tests, then re-run the checklist to validate
fixes.
Minimal-scope fixes first
Prefer small type-only changes, added runtime guards, or compatibility shims over API redesigns. Mark anything that blocks
merge as MUST FIX and include a minimal git-apply compatible diff to accelerate fixes.
Works Best With
Best used when you can provide the PR diff, tsc/CI logs, and a short list of downstream consumers
- Provide full unified diff/patch for the PR (not just a summary)
- Include tsc output and failing test logs so diagnostics can pinpoint regressions
- List public API files changed and known downstream consumers to verify migration impact
- State constraints (runtime compatibility required, no new deps) to prioritize shims over rewrites
Prompt Template
# Developer Productivity Prompt Blueprint (use EXACT section order)
## Goal
- Perform an engineering-grade automated review of a TypeScript API refactor pull request and produce a prioritized, actionable code-review checklist that drives a safe merge: hypotheses → diagnosis → fix plan → patch guidance → tests, plus migration and CI verification guidance.
## Inputs
Provide the following artifacts when running this prompt:
- PR title and PR description (including motivation and non-goals).
- Full file diff/patch for the PR in unified diff or git patch format (not a high-level summary).
- Test and CI output logs (failing tests, warnings, TypeScript / tsc output).
- package.json (project and any affected consumer packages) and tsconfig.json content.
- List of public API files/endpoints that changed and a short list of known downstream consumers.
- Any additional constraints (e.g., must preserve runtime compatibility, no new dependencies).
If any required input above is missing, ask explicitly for the minimal missing artifact(s) before performing the review.
## Prompt
You are an automated TypeScript API refactor review bot. Given the inputs listed above, perform a focused, minimal-scope, engineering-grade review and produce the exact structured output described below.
Rules for your analysis and outputs:
- Follow this sequence: generate hypotheses about regressions, run a diagnostic review of diffs and CI output, produce a prioritized fix plan, give minimal patch suggestions (unified-diff style or single-file minimal edits), and propose tests to add or strengthen. Present risk and merge blockers last.
- Do NOT assume files or runtime behavior not present in the provided diff or logs. If something is required but missing (types, public API contract, test), explicitly call it out as unknown and request it.
- Prioritize minimal, safe changes: prefer type fixes, small safe runtime checks, and deprecation shims over broad rewrites.
- For inline review comments use exact file path and a precise line hint. If line numbers are not available in the diff, include a 2-3 line code context snippet and the file path.
- For each proposed patch, provide a minimal unified-diff snippet (git apply compatible) or a clear code block showing the before and after with only the necessary changes.
- Mark items that must be fixed before merge with the prefix MUST FIX.
- Output must be in Markdown and strictly follow the Output Format and the list below.
Produce the following sections (in this order). Use bullet lists for each section and keep items concise and actionable.
1) Assumptions/Unknowns — list any missing inputs or assumptions you made.
2) Likely root causes (ranked) — 3-6 ranked hypotheses explaining regressions or type breakages.
3) Fix plan (ordered steps with owners and estimated effort) — an ordered checklist from highest to lowest priority.
4) Patch suggestions — prioritized inline comments and minimal diffs:
- Prioritized inline review comments with file/line hints and exact suggested code or type fixes.
- For each inline comment include rationale, risk, and whether it MUST FIX before merge.
- Include minimal unified-diff patches for each critical fix.
5) Test/verification checklist — concrete test cases to add or strengthen, with minimal reproduction steps and CI/local commands to run.
6) Migration plan snippet for downstream consumers — list breaking changes, compatibility shims or deprecation notes, and example migration code snippets showing before → after usage.
7) Recommended CI/local commands to reproduce issues and verification steps — exact commands (npm/yarn/pnpm, tsc flags, jest/mocha commands, Docker commands if relevant).
8) 1-paragraph risk summary — a concise paragraph and a numeric risk score (0-10) and the top 3 blockers to merge. Numbered blockers should be the most likely to prevent safe merge.
Additional output formatting constraints:
- Include an explicit "MUST FIX" label next to anything that blocks merge.
- For inline comments: use this structure per item:
- File: path/to/file.ts:lineNumber (or code context)
- Comment: one-sentence issue description
- Suggested change: minimal code snippet or unified-diff
- Rationale: one-line reason
- Risk: low/medium/high
- Merge requirement: MUST FIX / Should Fix / Optional
- For the Fix plan: include an owner role (e.g., maintainer, author, reviewer), estimated time (minutes or hours), and acceptance criteria for each step.
- For tests: provide exact test names, example assertions, and where to add them (file path).
- For migration snippets: provide concrete before/after call-site examples for consumers.
Do not add any additional narrative beyond the requested sections. Be concise, specific, and operator-grade.
## Output Format
Output:
1) Assumptions/Unknowns
2) Likely root causes (ranked)
3) Fix plan (steps)
4) Patch suggestions
5) Test/verification checklist
Additionally include:
- Prioritized inline review comments with file/line hints and suggested fixes
- Short list of missing or weakened tests with concrete test cases and reproduction steps
- Migration plan snippet for downstream consumers with breaking changes and example migration code
- Recommended CI/local commands to reproduce issues and verification steps
- 1-paragraph risk summary with a numeric risk score (0-10) and the top 3 blockers to merge
All outputs must be bullet lists, concise actionable items, and mark MUST FIX items explicitly.
## Guardrails
- Do not assume unseen files or tests exist; call them out as unknown.
- Prefer minimal diffs and type-only fixes where possible; avoid scope creep or large API redesigns in this review.
- Avoid introducing new runtime dependencies unless absolutely required; prefer compile-time/type-only changes.
- Preserve backward-compatible behavior when feasible; when breaking changes are required, provide a clear migration path and deprecation timeline.
- Keep patches small, testable, and reversible. If a fix is risky, propose a compatibility shim and a follow-up deprecation plan.
- If the diff touches public API files, treat all changes as potentially breaking and require explicit migration examples.
## Examples
- Mini root-cause + fix excerpt:
- Root cause: async function lost an await after refactor, returning Promise<unknown> where a value was expected.
- Fix excerpt (unified-diff):
--- a/src/handler.ts
+++ b/src/handler.ts
@@ -42,7 +42,7 @@ export async function handle(req: Request) {
- const result = fetchData()
+ const result = await fetchData()
return transform(result)
-}
+}
- Rationale: restores awaited value, fixes type mismatch and runtime undefined errors. Risk: low. Merge requirement: MUST FIX.
Variables
Usage Notes
Not for
- • Large architectural redesigns outside the provided diff
- • Non-TypeScript repositories or binary/native build issues
- • Full security audits or legal/compliance certifications
Do not include
- • Fabricated metrics or case studies
- • Model or internal system identifiers
- • Broad rewrites that exceed the patch scope specified in the PR
Sign in to save, like, or rate this prompt.
Canonical Examples
Input: PR: 'Refactor user API: normalize User type and make fetchUser async'. Changes: src/api/user.ts converts
fetchUser to async and returns UserV2 (email renamed to contactEmail, lastSeen optional). Tests not updated; CI shows
TypeScript errors and failing unit tests. Provided: unified diff for src/api/user.ts and src/types/user.ts, tsc output
showing type errors, package.json and tsconfig.json. Downstream consumers list: frontend-app, billing-service (not
included).
Loading result...
Failed to load output.
1) Assumptions/Unknowns: missing downstream test runs. 2) Likely root causes: API shape change, lost await. 3) Fix plan: MUST FIX type shim + runtime await. 4) Patch suggestions: inline comments and unified-diff to restore await and add compatibility shim. 5) Tests: add unit & integration assertions for both User and UserV2 shapes.
Why it works: Demonstrates the checklist catching type/contract
changes (renamed field, optional field), a missing await bug, failing tests, and provides minimal diffs + migration
guidance prioritized for safe merge.
Input: PR: 'API: rename getProfile(id) -> getProfile({ userId, includeMeta? }) and return
Promise<Profile|null>'. Changes: public exported function signature changed; types updated; internal callers
maybe not adjusted. Provided diff for src/profile.ts and tsconfig.json; CI shows tsc signature mismatch errors and some
unit test failures where older callsites still use positional id param.
Loading result...
Failed to load output.
Assumptions: downstream callers unknown. Likely root causes: public signature change and missing overload shim. Fix plan: add overload, runtime argument normalization, update tests. MUST FIX items include overload and CI green.
Why it works: Shows how the checklist detects signature and runtime
contract mismatches, offers a compatibility overload shim, minimal unified-diff patches, tests to add, and migration
examples for consumers.