TypeScript Error Diagnosis Prompts for Cryptic TS Errors

14 prompts to diagnose TypeScript errors fast — generics, conditional types, narrowing, module resolution, declaration files.

TypeScript errors are dense and often misleading — the line TS points at is rarely where the real problem lives, and the seven-line “Type A is not assignable to type B” wall hides one missing property three files away. These prompts force the model to walk back from the reported line to the actual cause, distinguish fixable code from bad types, and propose the minimum diff — not a sweeping rewrite or an as any patch. Pair with React component refactor prompts when the error lives in a React tree.

Best for

  • Daily TS development
  • Debugging library type errors
  • Migrating JS to TS
  • Reviewing PRs in TS codebases
  • Onboarding to a new TS codebase

1. Walk-back diagnosis

Below is a TypeScript error. Walk back from the reported line to find the real cause. Output: (a) what TS thinks is wrong, (b) what is actually wrong, (c) the minimum diff to fix, (d) whether to fix the code or the types.

Error:
{paste full error including filenames}

Code context:
{paste 20-30 lines}

2. “Type X is not assignable to Y” diagnosis

TS error: "Type {X} is not assignable to type {Y}". Diagnose: (a) what TS expected, (b) what it got, (c) the structural diff between X and Y, (d) is this a real bug or a type-narrowing issue.

Code:
{paste}

3. Generic-inference failure

TS failed to infer a generic. Below is the call site. Output: (a) what generics TS tried to infer, (b) which argument failed inference, (c) the explicit type annotation that fixes it, (d) whether the function signature needs improvement.

{paste code}

4. Conditional-type debugging

A conditional type is resolving to the wrong branch. Below: the type definition and a sample input. Walk through each conditional step, showing what TS computes at each step.

{paste type + usage}

5. Module-resolution debug

TS error: "Cannot find module {X}" or "Module {X} has no exported member {Y}". Diagnose: (a) tsconfig paths/moduleResolution, (b) package.json exports field, (c) declaration files, (d) the fix.

{paste error + tsconfig + package.json snippet}

6. Excess-property check confusion

Why does TS allow my extra property when assigned to a variable but not when passed inline? Below: code example. Explain TS's excess-property check rule and how to handle it correctly.

{paste}

7. Narrowing-not-narrowing diagnosis

I have a type guard but TS still complains about the narrowed type. Below: code. Diagnose why narrowing fails: (a) is the guard not user-defined, (b) is the value being aliased, (c) is TS losing the narrow due to async / closures, (d) the fix.

{paste}

8. .d.ts / ambient-declaration audit

My project uses {library} but its types are wrong or missing. Walk me through: (a) does it ship types, (b) is there an @types package, (c) do I need a custom .d.ts, (d) skeleton of the .d.ts I should write.

{paste imports + the type error}

9. tsconfig “strict” troubleshooting

I turned on {strict | noImplicitAny | strictNullChecks | exactOptionalPropertyTypes} and got {N} errors. Below: a representative 5. For each, classify (real bug / type-only / needs refactor) and propose the fix pattern.

{paste}

10. React-component-prop type fix

My React component has a TS error on its props. Below: component + usage. Diagnose: (a) prop type vs usage diff, (b) generic component issue, (c) HOC type loss, (d) the minimum fix.

{paste}

11. zod / yup / runtime-schema → TS type mismatch

My runtime schema ({zod / yup}) and TS type are out of sync. Below: schema + the inferred type vs the manual type. Diagnose the drift and propose how to keep them in sync.

{paste}

12. “any” hunt

Below is a file with implicit any's. List each, explain why TS could not infer, and propose the explicit type. Order by riskiest first.

{paste}

13. Migration: JS → TS, file at a time

I am migrating {file.js} to TS. Below: the file. Output a step-by-step migration plan: (a) types to introduce first, (b) the union/intersection structure that maps to the runtime shape, (c) which functions can stay loose for now.

{paste}

14. TS-error triage by impact

Below are 30 TS errors from `tsc --noEmit`. Triage into: (a) real bugs (fix code), (b) type-only (fix types), (c) needs refactor, (d) suppress with comment + reason. Order by blast radius.

{paste}

Common mistakes

  • Adding any to silence the error — moves the bug to runtime, where it’s worse
  • Trusting the reported line as the cause — it’s usually downstream of the actual mismatch
  • Casting with as without understanding the structural mismatch — silent hazard
  • Disabling strict or noImplicitAny to “make the build green” — sacrificing the whole reason to use TS
  • Fighting the type system instead of refactoring the underlying shape
  • Not pasting the full error chain — the second and third lines often name the actual culprit

Tags: #Prompt #AI coding #AI coding