How TypeScript Catches Incomplete Changes in AI-Generated Code

Your AI-Generated code passes TypeScript. What does that actually prove?

Anna Sobieraj-Kmiecik · October 30, 2026

AI coding agents can modify several parts of an application in minutes. The question is whether they have updated everything that depends on those changes.

In an established codebase, adding a role, changing an authorization rule, or extending a shared type can affect code far beyond the file being edited. An implementation may look correct in isolation while leaving a related configuration or handler unchanged.

TypeScript helps identify some of these incomplete changes, but only when the relevant relationships have been expressed in the type system. Understanding what those contracts catch, and what they cannot verify, is essential when using AI to maintain production applications.

What TypeScript actually catches

TypeScript performs static type checking: it analyzes how values are used and checks whether those operations are consistent with their declared or inferred types.

The simplest examples involve accessing a property that does not exist or passing an incompatible argument to a function. But TypeScript becomes more valuable when types represent meaningful relationships within an application.

Consider a B2B product in which an organization manages company-level access, while individual teams have their own permissions for viewing, editing, or managing team members.

Inviting someone to an organization is not the same operation as managing users within a team. TypeScript can encode that distinction:

type ActionsByLevel = {
  organization: "invite" | "admin" | "view";
  team: "view" | "edit" | "manage_users";
};

type Resource =
  | { kind: "organization"; id: string }
  | { kind: "team"; id: string };

type ActionFor<R extends Resource> =
  ActionsByLevel[R["kind"]];

An authorization function can use these types to associate actions with the appropriate resource level:

declare function assertAllowed<R extends Resource>(
  resource: R,
  action: ActionFor<R>
): Promise<void>;

const organization = {
  kind: "organization",
  id: "org-1",
} as const;

const team = {
  kind: "team",
  id: "team-1",
} as const;

assertAllowed(organization, "invite");       // OK
assertAllowed(team, "manage_users");          // OK

assertAllowed(organization, "manage_users"); // Type error
assertAllowed(team, "invite");                // Type error

When TypeScript knows the resource's specific kind, it can reject actions that belong to a different authorization level. For example, passing manage_users to an organization resource produces a type error because that action is defined only for teams.

The value here is not catching a typo. It is preventing two concepts that look similar in code from being treated as interchangeable. This is particularly useful during refactoring, when changes to shared authorization logic can affect multiple features.

However, this protection depends on preserving precise type information. If a resource is typed as the broader Resource union, the available action type can also widen to include actions from both resource levels. The generic signature alone does not guarantee that every combination is valid.

Consider a helper function that creates a team resource:

function resourceFromInput(teamId: string) {
  return { kind: "team", id: teamId };
}

Although the function always returns a team resource, TypeScript infers kind as string rather than the specific literal type "team". As a result, the returned object does not satisfy the Resource type defined earlier.

An explicit return type or as const can preserve the distinction:

function resourceFromInput(teamId: string) {
  return { kind: "team", id: teamId } as const;
}

Now TypeScript retains the information that this resource is specifically a team, allowing the authorization function to check its actions against the team-level permissions.

This illustrates an important aspect of AI-assisted refactoring: preserving the relationships encoded in types matters as much as defining them. A helper function may look correct in isolation, yet lose information that other parts of the application rely on.

Types also do not always have to be written manually. With tools like Supabase, TypeScript definitions can be generated from the database schema, helping keep application types aligned with the underlying data model. When the schema changes and types are regenerated, TypeScript can help identify code that still relies on outdated fields or data structures.

Configuration matters, too. TypeScript's strict option enables additional checks, while inaccurate declarations, unchecked JavaScript, and loosely typed boundaries can reduce the protection available.

When a type change requires updates elsewhere

Consider an application with three team roles: admin, editor, and viewer.

An AI coding agent is asked to introduce a fourth role, billing.

Updating the TypeScript union is straightforward. But the application may also maintain a catalog defining how each role appears in the interface. If the agent updates the union but misses the catalog, the implementation is incomplete.

TypeScript can detect that omission when the catalog is required to include every role:

type TeamRole =
  | "admin"
  | "editor"
  | "viewer"
  | "billing";

const ROLE_CATALOG = {
  admin: { label: "Admin" },
  editor: { label: "Editor" },
  viewer: { label: "Viewer" },
} satisfies Record<TeamRole, { label: string }>;

// Type error: "billing" is missing

The satisfies operator checks that the object conforms to the required structure without discarding its more specific inferred type.

The compiler reports the missing entry because the relationship between TeamRole and ROLE_CATALOG has been explicitly defined.

The same principle applies to resource loaders.

Suppose an authorization system needs to load additional attributes before evaluating access. When a new resource kind is introduced, the application must also register a loader for it.

A mapped type that requires one loader per resource kind can expose a missing registration, even when the domain model and loader registry live in different parts of the repository.

Without that relationship encoded in the types, the new resource definition and the existing registry may each look valid on their own.

TypeScript helps expose dependencies, provided the application models them explicitly.

That is particularly useful in AI-assisted development. An agent may update the files directly related to its task while overlooking a contract elsewhere in the repository. A well-designed type relationship turns some of those omissions into compiler errors.

When TypeScript reaches its limits

TypeScript is powerful, but it does not prove that a program is correct.

Its limitations fall into two categories: problems outside the scope of static type checking and limitations of the compiler's own type analysis.

Correct types do not guarantee correct business logic

Return to the organization and team authorization example.

TypeScript can prevent a team-only action from being passed to an organization resource when their relationship is represented in the type system.

But it cannot independently determine whether a particular user should be allowed to perform an otherwise valid action.

A correctly typed authorization check may still use the wrong resource ID, apply an incorrect business rule, or rely on incomplete access-control logic.

Similarly, adding a tenantId argument does not itself enforce tenant isolation. The server must still authorize access to the requested resource.

Static types help verify structural and contractual consistency. They do not automatically verify business intent or runtime security.

The compiler has limits too

TypeScript can also struggle with sufficiently complex type definitions.

Recursive conditional types and deeply nested type operations may produce errors such as TS2589: Type instantiation is excessively deep and possibly infinite.

As the TypeScript 4.5 release notes explain, the compiler uses heuristics to limit potentially infinite or computationally expensive type expansion. Even valid and useful type definitions can encounter these limits.

For AI-assisted development, this means that not every compiler error points to a mistake in application logic. Sometimes the appropriate response is to simplify a type definition, inspect dependency types, or investigate the compiler's behavior rather than repeatedly rewriting otherwise valid code.

Type assertions shouldn't replace validation

When TypeScript reports a type mismatch, the safest response is to investigate why the types disagree, not to silence the error with an assertion.

Consider the earlier authorization example. If an AI coding agent encounters a type error while passing a resource between functions, it could use as unknown as Resource to make the code compile. But that assertion does not restore the relationship between the resource kind and its permitted actions. It only bypasses the compiler's objection.

The same distinction matters at runtime boundaries. If an API returns data whose structure is not guaranteed, asserting that it matches a TypeScript interface does not make it valid. A schema validation library such as Zod can check the actual data before the application relies on it.

This deserves attention in AI-assisted development. A 2026 empirical study of TypeScript code found that AI coding agents used any and certain advanced type constructs more frequently than human developers. While that does not establish that agents routinely misuse assertions, it reinforces the importance of reviewing how generated code handles type safety.

Type assertions should be a deliberate exception, not a shortcut to a passing type check. For AI coding agents, the better default is to fix incorrect types, preserve precise type information, and validate uncertain external data rather than assert that it is correct.

Making TypeScript more effective with AI coding agents

TypeScript provides feedback after code has been written. But the way an AI agent is instructed to work can also influence how it responds to that feedback.

Project-level instruction files such as AGENTS.md and CLAUDE.md can specify coding conventions, verification commands, and expectations for handling type errors.

For example, a project might instruct its AI coding agent to investigate the cause of type errors, avoid introducing any without justification, check related catalogs and handlers when extending domain types, and run the project's type checker after modifications.

These instructions cannot guarantee correct code, but they can establish clear expectations before the agent begins making changes.

Anthropic's Claude Code best practices recommend documenting project commands and conventions in CLAUDE.md, including instructions to run the type checker after changes.

A more recent example comes from OpenAI's engineering team. In Using Skills to Accelerate OSS Maintenance, published in March 2026, OpenAI describes how it uses repository instructions, reusable agent skills, and GitHub Actions to maintain its Python and TypeScript Agents SDK repositories.

The relevant lesson is not that a particular instruction file makes AI-generated code reliable. It is that type checking becomes more useful when it is part of an explicit, repeatable feedback loop.

An agent can make a change, run the project's type checker, inspect the diagnostics, and revise its implementation. Developers can then review whether the reported errors were genuinely resolved and whether the code still satisfies the intended requirements.

For TypeScript projects, this creates a useful division of responsibilities: instructions guide the agent's approach, the compiler checks type consistency, and engineering judgment evaluates the result.

What this means for AI-assisted development at Feathered

At Feathered, type checking is one part of a broader engineering process. Repository instructions guide AI coding agents, automated tests verify behavior that types cannot express, and code review helps evaluate architectural and business decisions.

We also develop Preen, an open-source architecture linter for TypeScript monorepos. It checks repository structure, naming conventions, and import boundaries, rules that TypeScript's type checker does not enforce. Preen can also generate architecture instructions for AI coding agents, helping align their guidance with the repository's enforced conventions.

For database integration, we use Supabase with TypeScript types generated from the database schema. Regenerating those types after schema changes helps reveal outdated assumptions in application code.

These practices address different kinds of risk. Together, they help us evaluate changes beyond whether the code compiles.

Building an application with AI and preparing it for real customers?

At Feathered, we help founders evaluate technical decisions and understand the risks that matter as their products grow.

A technical audit can provide a broader assessment of architecture, implementation quality, and areas that need attention before the next stage of development.

Explore Feathered's services