# Add Are the Types Wrong to CI for a TypeScript Library

Yes. An agent packs your library, runs Are the Types Wrong against the tarball with the right profile, adds the check to CI with a config file, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-attw-to-ci/typescript-library/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads how the package is shaped before it runs anything, because the tool's whole job is to resolve the package the way each consumer does. In a library like sindresorhus/ky, `package.json` has `"type": "module"`, an `exports` map with only `types` pointing at `./distribution/index.d.ts` and `default` at `./distribution/index.js`, `main` and `types` set to the same two files for older resolvers, `"files": ["distribution"]`, `sideEffects: false` and `engines.node >=22`. `build` runs `del-cli distribution && tsc --project tsconfig.dist.json`, `prepare` runs the build, and `test` chains `xo`, the build, `tsc --project tsconfig.test.json` over the `test-d` type tests, and `ava`. `.npmrc` sets `package-lock=false`, so there is no lockfile and the workflow installs with `npm install`. `.github/workflows/main.yml` has a `test` job on a Node matrix of `latest`, 24 and 22 that runs `npx ava 'test/**' '!test/browser.ts'`, and a `browser` job that installs Playwright and runs `npm test -- test/browser.ts` once, with a comment saying the static checks belong there because they do not depend on the Node version.

The check runs against what npm would publish, not the working tree. The agent runs `npm run build`, then `npx --yes @arethetypeswrong/cli --pack .`, which packs the directory, inspects every entrypoint under each resolution mode and deletes the tarball. For an ESM-only package with no `require` condition the table shows a problem for CommonJS consumers under `node16-cjs`, reported as `cjs-resolves-to-esm`, while `node10` resolves through `main` and `types` and `node16-esm` and `bundler` resolve through `exports`. That CommonJS result is the package's stated design, so the agent sets the `esm-only` profile, which ignores CJS resolution failures, rather than ignoring the rule by name: a future change that broke `node10` or the ESM entry would still fail.

The configuration lives in `.attw.json` with `"profile": "esm-only"` so a maintainer running `npx attw --pack .` locally gets the same answer as CI. The workflow change is one step in the `browser` job, after `npm install` and before the Playwright step, running `npm run build` and the packed check with `--format table`, since that job already carries the once-only checks and the build is what `npm test` runs anyway. The agent pins the CLI's major version in the step. It also notes in the pull request that `exports` has no `require` condition, so if the team ever wants a CommonJS entry, the `esm-only` profile is the line to drop.

Then it proves the step fails when it should. In the sandbox it removes the `types` condition from `exports`, runs the check again and records the `untyped-resolution` row the table now shows, then restores the file. It runs `npm test` once so the pull request shows `xo`, the type tests and `ava` still pass with the new file present, and that `xo` does not lint the JSON config.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Add Are the Types Wrong to CI for this TypeScript library. Read package.json, .npmrc, tsconfig.json, tsconfig.dist.json, tsconfig.test.json and .github/workflows/main.yml first, and note the exports map, the type field, the engines range and that there is no lockfile. Run npm run build and then the attw CLI with --pack against this directory, read the table, and choose a profile that matches what the package means to support rather than ignoring rules by name; write it to .attw.json. Add one step to the job that already runs the once-only static checks, running the build and the packed check with a pinned CLI version. Break the exports map on purpose, show the failure the check reports, restore it, and run npm test. Open a pull request with the table from the passing and the failing run and why the profile is the right one for this package.",
  "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

A pull request that adds `.attw.json` and one step to `main.yml`, and changes nothing in the package itself. The description shows the resolution table for the packed tarball under each mode, the row the deliberate break produced, the reasoning for `esm-only` over an ignored rule, and the `npm test` output with the config file present.

A reviewer checks that the profile matches what they mean to support, that the CLI version pin is one they are happy to bump through Dependabot, and merges. From then on a change to `exports`, a missing `.d.ts` in `distribution` or a `tsconfig.dist.json` edit that stops emitting declarations fails the `browser` job before a release goes out.

## Run it on every terminal hand-off

A maintainer who has just answered an issue about a missing type starts this from the terminal with this body and the repository in `resources`, and goes back to the issue. The run reads the real `exports` map and the real workflow, so the profile is chosen from what the package publishes and the step lands in the job that already runs the static checks.

Send a `request_id`, a UUID, with the body so a retried start returns the run it already began. When the turn ends, `GET /o/{org}/sessions/{id}` names the pull request, and a follow-up to the same session can ask for a `require` condition with a CommonJS build and the profile changed to `strict`, or for the same check on a second package in the organisation.

## Why run it on Rush?

The decision is which resolution modes a package promises, and the only way to make it well is to pack the library and read the table for its own entrypoints. The agent does that in its own sandbox, including the deliberate break that shows the step has teeth, and keeps every command and both tables in the run's record, so the pull request shows what consumers resolve rather than describing a tool.

The same run fits any published TypeScript package: a dual ESM and CommonJS build where the `strict` profile is right and `false-cjs` is the rule to watch, a package with several entrypoints under `exports` where each gets its own row, or a monorepo where the step runs per workspace with pnpm's `pack` output passed as a tarball. Each gets a profile derived from its own `package.json` and a check that runs where its CI already builds.

## Frequently asked questions

### Why a profile instead of ignoring the CommonJS rule?

`--ignore-rules cjs-resolves-to-esm` silences one named problem everywhere, including a future entrypoint where it would be a real bug. The `esm-only` profile says the package does not support CommonJS resolution at all, which is what `exports` with no `require` condition and `engines.node >=22` already state, and leaves every other mode strict.

### Does it need a lockfile or npm ci?

No. `.npmrc` turns off the lockfile, so the step uses `npm install` like the rest of the workflow, and `--pack` runs `npm pack` on the built directory. A repository on pnpm or yarn packs with its own tool and passes the tarball path instead.

### What does the check catch that tsc does not?

`tsc` proves the sources compile; it says nothing about whether a consumer's resolver finds the declarations the package ships. Are the Types Wrong resolves each entrypoint the way `node10`, `node16` and bundlers do and reports a missing or mismatched `.d.ts`, a `types` condition in the wrong place, or a default export that CommonJS would see as an object.

### Where should the step run?

In the job the workflow already reserves for checks that do not depend on the Node version, so it runs once per push rather than once per matrix row. It needs the build output, so it runs after `npm install` and the build and before the browser tests.

## More TypeScript library jobs

- [Add a Bundle Size Check to a TypeScript Library from a Linear Issue](https://getrush.ai/run/add-bundle-size-check/typescript-library/)
- [Add Changesets to a TypeScript Library](https://getrush.ai/run/add-changesets/typescript-library/)
- [Add CodeQL Scanning to a TypeScript Library](https://getrush.ai/run/add-codeql-scanning/typescript-library/)

## More jobs like this: Hand off a long task

- [Add an Audit Log to a Fastify API](https://getrush.ai/run/add-audit-log/fastify/)
- [Add an Audit Log to a Filament Admin Panel](https://getrush.ai/run/add-audit-log/filament/)
- [Add an Audit Log to a Mongoose and Express API](https://getrush.ai/run/add-audit-log/mongoose/)

## 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/)
