Fix TypeScript Type Errors
Resolve stubborn type errors by reading what the compiler is really saying, with fixes ranked so escape hatches are the last resort.
Help me fix this type error. The full error, unabridged: """ [PASTE THE ENTIRE ERROR INCLUDING EVERY "Types of property X are incompatible" LINE. THE NESTED PART IS USUALLY THE REAL ERROR.] """ The code: """ [PASTE THE FAILING CODE PLUS THE TYPE AND INTERFACE DEFINITIONS INVOLVED] """ TypeScript version and relevant tsconfig settings: [strict, strictNullChecks, exactOptionalPropertyTypes, moduleResolution] What I am trying to express: [THE INTENT IN PLAIN LANGUAGE] What I have tried: [ATTEMPTS SO FAR] Do this: 1. **Translate the error.** State in one plain sentence what the compiler is actually complaining about, working from the innermost nested message outward. Long type errors are usually one small mismatch reported through several layers of structure. 2. **Say whether the compiler is right.** Most of the time the type error is a real bug the types caught: a value that can be undefined, a union member not handled, a mutation that breaks an assumption. Say which case this is before proposing anything, because that decides whether we are fixing code or fixing types. 3. **Rank the fixes**, best first, with the tradeoff for each: - Fix the runtime code so the types are satisfied honestly - Correct the type definition to describe reality (often the types were wrong, not the code) - Narrow properly: a type guard, a discriminated union, an exhaustive switch, a schema parse at the boundary - Change the generic constraint or add the missing type parameter - Last resort: an assertion or an escape hatch, and only with a comment stating why it is safe and what would make it unsafe 4. **Give the fixed code** for your top recommendation, with the changed lines marked and the reasoning in one line. 5. **Check the blast radius.** What else this change affects: other callers, inferred return types downstream, and whether it widens or narrows a public type. Rules: never suggest any, a non-null assertion, or a type cast as the first option, and never suggest suppressing the error to make it go away. If the honest fix requires refactoring beyond what I pasted, say so and describe it rather than papering over it. If the error message alone is not enough, name the exact additional type or file you need.
How to use
Paste the complete error including the deeply indented tail, which is where the actual mismatch is stated and which people usually truncate because it looks like noise. Step 2 is the one that changes outcomes: the instinct with a stubborn type error is to silence it, and a meaningful share of the time the compiler has found a genuine null or an unhandled union case, so silencing it converts a build error into a production one.
More coding prompts
Write the commit message for this change. Diff: """ [PASTE THE STAGED DIFF] """ Why I made this change: [THE REASON, THE TICKET, THE BUG REPORT, or "you infer it"] Convention: [Conventional Commits / this repo's existing style, pasted below / plain] Recent commits from this repo, to match style: """ [PASTE 5-10 RECENT COMMIT SUBJECT LIN
Commit Message
Write a commit message that explains why the change was made, in Conventional Commits format, split into separate commits when needed.
Help me recover from a git mistake without making it worse. What I was trying to do: [THE GOAL] What I ran: [THE EXACT COMMANDS, IN ORDER] What happened instead: [THE OUTPUT OR THE STATE NOW] Has this been pushed or shared: [YES/NO, and to which branch and whether anyone else has pulled] Uncommitted work I cannot lose: [WHAT AND WHERE, o
Undo a Git Mistake
Recover from a bad commit, force push, wrong branch, or lost work with a reversible plan and the exact commands, explained before you run them.
Handler code, routes, and models: """ [PASTE THE ROUTE DEFINITIONS, HANDLERS, REQUEST AND RESPONSE TYPES, VALIDATION SCHEMAS, AND MIDDLEWARE] """ Generate an OpenAPI 3.1 specification from the code above. API name, version, and base URL: [DETAILS] Auth scheme: [BEARER JWT / API KEY / OAUTH / SESSION COOKIE, and where it is enforced] Con
OpenAPI Spec From Code
Generate an accurate OpenAPI 3.1 spec from handler code, including error responses and auth, with gaps flagged instead of invented.