# Fix TypeScript Errors After an Upgrade

An agent moves a NestJS app from TypeScript 3.9 to 7.0.2, takes tsc --noEmit from 40 errors to 0 without casts, and starts the app against MariaDB.

[Run this on Rush](https://cloud.getrush.ai/run/fix-type-errors/nestjs/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

Before upgrading, the agent ran `tsc --noEmit` on the untouched clone: 40 errors, all syntax errors in `node_modules/@types/babel__traverse` that TypeScript 3.9 cannot parse, so `src` was never checked. Moving to `^7.0.2` gave 69, bumping `@types/jest` and `@types/node` removed 2, and making typeorm 0.2 resolvable through `moduleResolution` exposed 121 strict-null errors the unresolved import had hidden.

The fixes: definite-assignment `!` on 41 entity and DTO fields, an `assertFound` helper in `src/shared/assert-found.ts`, `JwtUserPayload` with the `isJwtUserPayload` guard in `src/shared/jwt.ts`, a `declare global` extension of Express's `Request` in `src/user/user.interface.ts`, and `src/shared/inject-repository.ts` for 8 parameter-decorator errors from Nest 7's types.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Upgrade TypeScript to the latest version in this project and record the tsc --noEmit error count before and after. Copy src/config.ts.example to src/config.ts in the sandbox only. First update outdated @types packages and record how many errors that removes. Then fix every remaining error with real types: no any, no casts to unknown, no ts-ignore or ts-expect-error. Type jwt.verify payloads with an interface and a type guard, and extend Express's Request for req.user with a declaration. Start MySQL from ormconfig.json.example, run npm test, build and start the app. Open a pull request with the error counts at each step and a list of each fix grouped by cause.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

Tried on lujakob/nestjs-realworld-example-app at c1c2cc4: 26 files changed, 212 insertions(+), 116 deletions(-). `tsc --noEmit` exited 0, as did a build into `node_modules/.cache/dist-build` (the tracked `dist/` stays stale), and `npm test -- --forceExit` ended `Tests:       1 passed, 1 total`. Without `--forceExit` jest never exits, on the untouched clone too, because the TypeORM connection stays open. MySQL was not installed, so the agent installed MariaDB 10.11 with a throwaway `ormconfig.json`; the app served register, login and `GET /api/user`.

For the reviewer: a missing article, profile or user now returns 404 (401 for `findByEmail`) instead of a 500 or `200 {}`. The lockfiles were not regenerated: `package-lock.json` pins 194 tarballs to a host with a self-signed certificate, so the run used `yarn install --no-lockfile`, and ts-jest and ts-node now run on `@typescript/typescript6`.

## Run it on every Monday, on a schedule

An automation with a `schedule` trigger, `cron` `0 9 * * 1`, runs a saved prompt each Monday. The recipe's prompt takes minor versions only and leaves out breaking upgrades, so save this request instead, telling it to report the current version and open nothing when no newer TypeScript exists. A breaking week shows the error count per step, like this run's 40, 69, 67, 121, 122, 0.

## Why run it on Rush?

The untouched clone's 40 errors were not the app's: a type package the old compiler could not parse stopped tsc before it reached `src`. The real build then caught what `--noEmit` could not: without `rootDir`, TypeScript 7 wrote `dist/src/main.js`, which would break `start:prod`.

## Frequently asked questions

### Did the agent use any or casts?

It added no casts, `ts-ignore` or `ts-expect-error`, and removed explicit `any` from the validation pipe, the user decorator, `ArticleService.update` and the base controller. `noImplicitAny` stays `false`, so parameters such as `query` and `where` are still implicitly `any`.

### Why skipLibCheck and a new module resolution?

typeorm 0.2's `exports` has only a `node` condition, so `tsconfig.json` sets `moduleResolution: bundler` with `customConditions: ["node"]`, and typeorm's own `.d.ts` files fail under TS 7.

## More NestJS jobs

- [Fix Vulnerable Dependencies in a NestJS App](https://getrush.ai/run/fix-vulnerable-dependencies/nestjs/)
- [Generate a Typed API Client for a NestJS Service](https://getrush.ai/run/generate-api-clients/nestjs/)
- [Investigate a NestJS API Incident With Datadog](https://getrush.ai/run/investigate-incidents-with-datadog/nestjs/)

## More jobs like this: Upgrade dependencies weekly

- [Fix Type Has No Properties in Common With FindOneOptions After a TypeORM Upgrade](https://getrush.ai/run/fix-type-has-no-properties-in-common-with-findoneoptions/typeorm/)
- [Fix "styled-components: it looks like an unknown prop is being sent through to the DOM" After Upgrading to 6](https://getrush.ai/run/fix-unknown-prop-is-being-sent-through-to-the-dom-warning/styled-components/)
- [Fix "AttributeError: module 'urllib3.util.ssl_' has no attribute 'DEFAULT_CIPHERS'" After Upgrading Requests](https://getrush.ai/run/fix-urllib3-default-ciphers-attribute-error/urllib3/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
