OctiAI

Categories

TypeScript API Refactor Checklist

PR-focused, acceptance-criteria driven checklist to detect API breaks, type/runtime mismatches, security gaps, and CI/test regressions during TypeScript API refactors.

What You'll Get

How to Use

Fast triage tip

First run npx tsc -p tsconfig.json and the repository test command (e.g., npm test or pnpm -w test) to catch compile-time and test regressions. Prioritize public API compatibility and any runtime validation gaps — those cause the highest-severity production failures.

Works Best With

Works best when the PR includes these minimal inputs

Prompt Template


# Developer Productivity Prompt Blueprint (use EXACT section order)

## Goal
Produce a concise, PR-focused code review checklist and actionable reviewer output for a TypeScript API refactor that, when applied to a pull request, drives: hypotheses → diagnosis → prioritized fix plan → patch guidance → tests — all in an operator-friendly, acceptance-criteria driven format.

## Inputs
Provide the following inputs with the PR or paste them inline. If any are missing, ask the requester only for the minimal missing artifacts before proceeding.
- PR diff or branch name and the repository root path (or a zipped list of changed files with contents).
- List of changed files (paths) and the most important file snippets if the diff is large.
- tsconfig.json and package.json from the repo root.
- Existing public API contract: exported types/interfaces, OpenAPI/Swagger spec, or previous version changelog.
- CI pipeline file(s) that run tests/builds (e.g., .github/workflows, bitbucket pipelines).
- Test command(s) (e.g., npm test, pnpm -w test, jest --coverage).
- Short description of the refactor intent and semantic-versioning expectation (patch/minor/major).

If any input is not supplied, request precisely only the missing item(s) and halt until provided.

## Prompt
You are an expert TypeScript API code reviewer and maintainer. Given the provided Inputs, perform a PR-focused review that produces five deliverables: Assumptions/Unknowns, Ranked Likely Root Causes, a Stepwise Fix Plan, Concrete Patch Suggestions, and a Test/Verification Checklist. Output must be concise, deterministic, and actionable.

Procedure requirements (must be followed exactly):
1. Quickly infer and list any Assumptions/Unknowns about missing context.
2. Generate 3-6 ranked Likely Root Causes for observed or probable issues introduced by the refactor (rank high→low).
3. Produce a Fix Plan as an ordered checklist of concrete steps (minimal-diff prioritized). For each step include owner (reviewer or author), estimated effort (mins), and a single acceptance criterion.
4. Provide Patch Suggestions as small, copy-paste-ready diffs or code hunks with exact file paths and the precise change. When recommending new dependencies, justify necessity and show package.json diff and any tsconfig or build changes.
5. Provide Test/Verification Checklist with commands to run, exact test files to add/modify (with sample tests), and CI expectations.

For each checklist item you produce later in the PR checklist, include:
- Inspect: exact file patterns or code patterns to review (e.g., src/controllers/*.ts, src/routes/*.ts, export type .* from '.*', new exported interfaces).
- Verify: exact verification commands or steps (e.g., npx tsc -p tsconfig.json, node --verify, jest --coverage --findRelatedTests <files>, curl -s -X POST ... against local server).
- Acceptance criteria: concrete pass/fail criteria expressed in observable terms (e.g., "All public exported types remain binary-compatible; tests pass with coverage >= 85%").
- Remediation: exact remediation steps and minimal code examples or patches to fix the issue.

Ensure the checklist explicitly covers:
- Public API contract: exported types/interfaces, request/response shapes, semantic-versioning implications and suggested version bump.
- Type vs runtime mismatches (type-only changes vs runtime behavior, missing runtime validation).
- Unit/integration/test coverage gaps and required test additions.
- Behavioral/regression risks and suggested smoke tests.
- Security concerns: input validation, auth/authorization changes, injection vectors, widened attack surface.
- Dependency/build changes: new deps, peerDeps, bundler/tsc/ESM/CJS impacts.
- Deprecations and migration guidance for consumers (how to migrate, deprecation warnings).
- Documentation and changelog updates required.
- CI expectations: which pipeline jobs must run and pass.

Output formatting instructions:
- Use Markdown headings and ordered lists.
- For each checklist item use the fields: Inspect, Verify, Acceptance criteria, Remediation.
- When providing patches use unified-diff style hunks beginning with filenames and context lines (no inline commentary inside diffs).
- End with a 3-line prioritized risk summary (High/Medium/Low) and a final "Top 5 reviewer flags" list — five terse reviewer-required changes that must be addressed before merging.

If required inputs are missing, pause and list precisely which inputs are missing; do not guess those contents.

Now analyze the provided Inputs and produce the required deliverables.

## Output Format
Output:
1) Assumptions/Unknowns  
2) Likely root causes (ranked)  
3) Fix plan (steps)  
4) Patch suggestions  
5) Test/verification checklist

Each of the five outputs must be present and clearly labeled.

## Guardrails
- Do not assume any files or behavior not present in the provided Inputs. If you must, call that out under Assumptions/Unknowns.
- Prefer minimal diffs; changes should affect the smallest number of files required.
- Avoid proposing large refactors, major dependency upgrades, or infrastructural changes unless the refactor inherently requires them and the author has indicated approval.
- When suggesting breaking changes to the public API, include explicit semantic-versioning guidance and a migration snippet for consumers.
- When recommending new runtime validation libraries or dependencies, include a short justification and the exact package@version and the smallest example usage required.
- Provide exact commands and CI job names to validate fixes (e.g., npm run build && npm run test, npx tsc -p tsconfig.json).

## Examples
Mini root-cause + fix excerpt:

Root cause (example): A new exported type MyApiResponse includes a field as optional (foo?: string) but request-handling code assumes foo is present and uses foo.length at runtime, causing crashes.

Fix excerpt:
- Inspect: src/handlers/*.ts, src/types/*.ts (look for "foo?" and runtime uses of foo.length)
- Verify: Run npx tsc -p tsconfig.json && node ./dist/server.js and run jest --findRelatedTests src/handlers/fooHandler.test.ts
- Remediation patch (example unified diff):
--- a/src/handlers/fooHandler.ts
+++ b/src/handlers/fooHandler.ts
@@ -12,7 +12,11 @@
-  const length = req.body.foo.length;
+  const foo = req.body.foo;
+  if (typeof foo !== 'string' || foo.length === 0) {
+    throw new BadRequestError('foo must be a non-empty string');
+  }
+  const length = foo.length;

- Test addition (example):
--- a/tests/fooHandler.test.ts
+++ b/tests/fooHandler.test.ts
@@ -1,6 +1,12 @@
+test('returns 400 when foo missing', async () => {
+  const res = await request(app).post('/api/foo').send({});
+  expect(res.status).toBe(400);
+});
+
 test('returns length when foo present', async () => {
   const res = await request(app).post('/api/foo').send({ foo: 'bar' });
   expect(res.body.length).toBe(3);
});

Three-line prioritized risk summary (example):
- High: Runtime crashes from missing runtime validation of newly exported optional fields.
- Medium: Public API shape changed without migration guidance → consumer breakage.
- Low: Minor test coverage gaps for edge cases.

Top 5 reviewer flags (example):
1. Missing runtime validation for changed exported types — block.
2. No unit/integration tests covering new request shapes — block.
3. Public API contract changed without version bump or changelog entry — block.
4. New dependency added without justification/lockfile changes — consider blocking.
5. TS compilation warnings or suppressed errors (// @ts-ignore) introduced — require removal.

Variables

Usage Notes

Not for

Do not include

Sign in to save, like, or rate this prompt.

Canonical Examples

Input: PR: Type change in API response 'UserProfile' -> made 'id' optional; changed src/types/user.ts and src/handlers/userHandler.ts. tsconfig.json and package.json provided. Tests exist but do not cover missing id. CI jobs: build, test.

Loading result...

Failed to load output.


High risk: handler uses user.id without guard -> runtime crash. Fix: add runtime guard + return 400, or restore type to required and bump patch/minor accordingly.

Why it works: This output targets a common refactor: an exported type made optional while runtime code still assumes presence. It shows an inspector-focused checklist, minimal patches to add runtime validation, and tests to prove behavior, enabling quick reviewer decisions.

Input: PR: Renamed exported client function getUser -> fetchUser and replaced param shape from (id: string) to (opts: { id: string; includeMeta?: boolean }). Files changed: src/client/index.ts, src/client/README.md. package.json and tsconfig.json included. Author didn't indicate semver intent.

Loading result...

Failed to load output.


Provide deprecation wrapper `getUser(...)` calling new `fetchUser(...)`, add tests for both shapes, add CHANGELOG migration, and recommend major/minor bump depending on intent.

Why it works: This demonstrates handling a breaking public API rename and parameter-shape change. The output offers a compatibility shim, migration guidance, semver recommendation, tests, and CI checklist to help reviewers triage and accept or require changes.