All jobs

Fix Type Has No Properties in Common With FindOneOptions After a TypeORM Upgrade

Yes. An agent typechecks against typeorm 0.3, rewrites every findOne(id) as findOneBy or an options object, handles the null result and opens a PR with tsc clean.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent clones the repository into its own cloud sandbox and reads how the data layer is called. In a Fastify service like gergof/filaman-server, package.json pins typeorm at ^0.2.41 with mysql2 ^2.3.3, fastify ^3.25.3 and typescript ^4.5.4, tsconfig.json is strict, and the scripts are typecheck: tsc --noEmit, build: rimraf build && cross-env NODE_ENV=production tsc and start: ts-node ... src/index.ts. src/Db.ts imports getConnectionManager and FindCondition and creates a mysql connection with synchronize: true over the nine entities in src/models. The eight route files call the 0.2 shapes everywhere: .findOne(req.params.id), .findOne(req.body.imageId), .findOne(req.params.id, { relations: ['image'] }) and .update(material, patch).

Then it shows what breaks. At the locked 0.2.41, npm run typecheck is clean. After npm install typeorm@0.3, tsc --noEmit reports errors of four kinds: Type 'number' has no properties in common with type 'FindOneOptions<Material>' (TS2559) where an id was passed alone, Expected 1 arguments, but got 2 (TS2554) where relations were the second argument, TS2345 where an entity was passed as the update criteria or a route handler now returns Promise<Material | null | undefined> against a reply schema that has no null, and TS2305 because FindCondition is no longer exported. npm install typeorm@latest does not even install: npm stops with ERESOLVE because the 1.x line wants a mysql2 3.x as an optional peer and the repository pins ^2.3.3.

The rewrite is mechanical and the agent does it file by file: .findOne(id) becomes .findOneBy({ id }), .findOne(id, { relations }) becomes .findOne({ where: { id }, relations }), .update(entity, patch) becomes .update(entity.id, patch), and FindCondition<any> becomes FindOptionsWhere<any>. One route is not mechanical: the materials PUT handler returns the re-read entity directly, and findOneBy can return null, so the agent adds the same not-found branch the GET handler already uses. With those changes tsc --noEmit reports nothing on 0.3.

It stops short of the 1.x line and says why: the mysql2 peer range is a second upgrade with its own driver changes, and getConnectionManager is deprecated in 0.3 in favour of DataSource, which is a structural change to src/Db.ts rather than a type fix. Both are listed in the pull request as the next two changes, in that order. The repository has no test script, so the proof is the typecheck and the build.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "tsc fails in this TypeScript service after upgrading typeorm: \"Type 'number' has no properties in common with type 'FindOneOptions<...>'\". Read package.json, tsconfig.json, the data-source or connection setup and every file that calls a repository method first. Run the typecheck at the locked typeorm version, then install typeorm 0.3 and run it again, quoting the error count and one example of each error code. Rewrite each findOne(id) as findOneBy({ id }), each findOne(id, options) as findOne({ where: { id }, ...options }), each update(entity, patch) as update(entity.id, patch), and replace removed type exports with their 0.3 names. Wherever a handler returned the result directly, handle the null that findOne now returns. Do not move to DataSource or change the driver version in this change; list them as follow-ups. Run the typecheck and build until clean, run any tests, and open a pull request that quotes the error count before and the clean run after.",
  "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

What comes back is a pull request touching package.json, package-lock.json, src/Db.ts and the route and helper files that call findOne, update and FindCondition, with one added not-found branch in the materials PUT route. The description quotes the error summary grouped by code from the upgraded typecheck, the clean tsc --noEmit after the rewrite, and the ERESOLVE output that explains why the pull request lands on 0.3 and not 1.x.

A reviewer checks that every where key is the entity's primary column, that no relation was dropped when relations moved inside the options object, that the new null branches answer with the same helper the neighbouring routes use, and that synchronize: true in Db.ts is still what the team wants before this runs against a real database. The run's record keeps both typecheck outputs in full.

Run it on every Monday morning

Add an automation to the Project with this prompt and a schedule trigger, cron set to 0 9 * * 1 in your timezone. Each Monday one run bumps typeorm, typechecks and builds, and opens one pull request on its own branch; a week where the typecheck cannot be made clean ends needs_review with the error list attached, and a week already on the target major opens nothing.

The same body works from your own code with POST /o/{org}/sessions and an API key when a dependency bot's typeorm bump fails its checks; the key's webhook_url receives run.completed or run.failed with the session URL and the pull request when the run ends.

The use case this job follows, with its automation and trigger: Upgrade dependencies weekly.

Why run it on Rush?

An error list across eight files is the kind of upgrade that gets postponed for a year, not because any one edit is hard but because doing them by hand on a laptop, with a MySQL service and a running app in the way, takes an afternoon nobody has. The agent does the rewrite in its own sandbox against the typechecker alone, and every tsc run stays in the run's record, so the pull request shows the error count falling to zero rather than asserting it.

It also keeps the upgrade honest about its edges. The agent tried the newest release and quotes why npm refused it, and it names the DataSource migration as the next change instead of smuggling a connection rewrite into a type fix. What comes back is one reviewable pull request with the proof attached, and a short list of what the next one should be.

Frequently asked questions

Why findOneBy and not findOne({ where }) everywhere?

Both are 0.3 shapes. findOneBy({ id }) is the direct replacement for findOne(id) and reads the same; findOne({ where, relations }) is needed when relations or other options are passed. The agent uses the shorter one where nothing else was passed, and the options object where something was.

What about findOne returning null now?

In 0.2 a missing row came back as undefined; in 0.3 findOne and findOneBy return null. Most of this repository's routes already test the result and answer not-found, so they are fine; the one handler that returned the re-read entity straight to a reply schema without null gets the same not-found branch as its neighbours.

Why not go straight to typeorm 1.x?

Because npm will not install it against this repository as it is: the 1.x line declares a mysql2 3.x as an optional peer and the project pins ^2.3.3. Bumping the driver is its own change with its own behaviour to check against a database, so the pull request stops at 0.3 and names the driver bump as the next step.

Does the agent need a MySQL database to do this?

No. This change is proven by tsc --noEmit and the build, which is what the repository's own scripts offer; it has no test suite. A run against a real database belongs to the DataSource follow-up, where connection behaviour actually changes.

More TypeORM jobs

More jobs like this: Upgrade dependencies weekly

Keep reading