Andrej Karpathy posted the term in February 2025: "There's a new kind of coding I call 'vibe coding', where you fully give in to the vibes, embrace exponentials, and forget that the code even exists." (source) Plenty of developers recognized themselves in it.
Vibe coding isn't reckless by definition: it's what happens when AI tools get good enough that you can describe intent and review output instead of writing every line. Karpathy's own example was talking to Cursor's Composer through a dictation tool and accepting changes without reading the diffs. That speed is real, and nobody who's felt it wants to give it back.
The defect numbers are the other side of it. CodeRabbit's December 2025 analysis of 470 pull requests (320 AI-co-authored, 150 human-only) found the AI-co-authored ones carried about 1.7x more issues overall. And GitHub's Octoverse report cites a 2025 study in which 94% of LLM-generated compilation errors were type-check failures. The study itself (Mundler and colleagues, listed in the sources below) puts it as an average across the models it evaluated.
Put that last number next to what TypeScript is for. Nearly all the compilation errors AI code produces are type errors, and catching type errors at compile time is the compiler's whole job.
TypeScript isn't a nicety for vibe coding. It's the only safety net that makes it sustainable.
Where pure vibe coding fails at scale
When you ask an AI to "add a user dashboard," it writes plausible-looking code fast, and plausible isn't the same as correct. AI models predict what tokens should follow, they don't execute your code mentally and verify the logic.
The defects follow predictable patterns, and these four are the ones the gates below are designed around:
- Functions typed as returning
anywhen the actual shape matters downstream - API responses wrapped in
Record<string, unknown>instead of a real interface - Optional chaining skipped:
user.profile.nameinstead ofuser.profile?.name - Array access assumed safe:
items[0].idon a list that might be empty
None of these fail on the happy path in development. They crash in production, for the one user who hits the edge case. Sound familiar?
TypeScript catches all four at compile time, but not with strict: true alone. The optional-chaining case is strictNullChecks, which strict turns on. The empty-array case needs noUncheckedIndexedAccess, which strict does not include. And an explicit any return type compiles under every flag, which is why gate 3 below exists.
The quality-first framework
The quality-first framework is a set of four sequential TypeScript checks aimed at the type-related defects AI assistants introduce: wrong data shapes, unsafe array access, unsafe assertions, and malformed data crossing the network boundary. Three of the four are configured once and then run automatically on every commit, with no manual review step for the type-level checks; the first one is a habit you repeat per feature.
The quality-first framework runs four gates in sequence: types before prompts, a minimum strict tsconfig, typescript-eslint's strict-type-checked ruleset, and Zod validation at runtime boundaries, each one targeting a different failure mode AI-generated code introduces, from wrong data shapes to malformed responses crossing the network.
Step 1: Types Before Prompts
Don't ask AI to "write a function that fetches user orders." Instead, define the shape of the data first:
interface Order {
id: string;
userId: string;
items: OrderItem[];
status: 'pending' | 'shipped' | 'delivered' | 'cancelled';
total: number;
createdAt: Date;
}
interface FetchOrdersResult {
orders: Order[];
nextCursor: string | null;
total: number;
}
Now prompt with the contract attached: "Write a fetchOrders(userId: string, cursor?: string): Promise<FetchOrdersResult> function using these types."
Two things happen. The AI has a precise contract rather than guessing the return shape. And when it generates the implementation, TypeScript checks that the output actually satisfies FetchOrdersResult. A wrong shape is a compile error on the spot instead of a crash in production hours later.
Step 2: The Minimum tsconfig
Your tsconfig.json for any vibe coding project:
{
"compilerOptions": {
"strict": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"noImplicitReturns": true,
"target": "ES2022",
"moduleResolution": "Bundler"
}
}
strict: true is non-negotiable. The tsconfig reference describes the strict mode family it switches on: eight flags on TypeScript 7.0 (nine on 5.6 through 6.x, when alwaysStrict still counted), including strictNullChecks, noImplicitAny and useUnknownInCatchVariables. noUncheckedIndexedAccess makes array indexing return T | undefined, so items[0] forces you to handle the empty case rather than assume. exactOptionalPropertyTypes stops AI from assigning undefined to optional properties that don't accept it.
The full breakdown of every strict flag is in the TypeScript strict mode guide.
Step 3: typescript-eslint Catches What tsc Misses
The TypeScript compiler and ESLint with typescript-eslint have different coverage. The compiler checks types. ESLint catches patterns that are technically valid TypeScript but almost always indicate AI-generated bugs:
npm install -D eslint @eslint/js typescript-eslint
ESLint 9 made the flat config the default and ESLint 10 dropped .eslintrc entirely, so the config is an eslint.config.mjs file:
// eslint.config.mjs
import eslint from '@eslint/js';
import { defineConfig } from 'eslint/config';
import tseslint from 'typescript-eslint';
export default defineConfig(
eslint.configs.recommended,
tseslint.configs.strictTypeChecked,
{
languageOptions: {
parserOptions: {
projectService: true,
},
},
},
);
On a TypeScript 7 project the install stops on typescript-eslint's peer range first; the typescript-eslint peer range fix covers the two-package workaround.
strictTypeChecked already sets no-explicit-any, no-non-null-assertion and no-unsafe-assignment to error, so there's nothing to add by hand. Those three rules block any, the ! non-null assertion operator, and unsafe assignments. AI assistants reach for all three constantly when they can't infer an exact type. Treating them as errors forces the AI (or you in the review) to be explicit.
Step 4: Zod at Runtime Boundaries
TypeScript disappears at runtime. External API responses can return anything regardless of what your types say. The one gap in TypeScript's protection is the boundary where external data enters your system, fetch responses, localStorage reads, URL params.
Zod closes that gap:
import { z } from 'zod';
const OrderSchema = z.object({
id: z.string(),
userId: z.string(),
items: z.array(z.object({
productId: z.string(),
quantity: z.number().positive(),
price: z.number()
})),
status: z.enum(['pending', 'shipped', 'delivered', 'cancelled']),
total: z.number(),
createdAt: z.coerce.date() // JSON carries a string; this turns it into the Date the interface promises
});
type Order = z.infer<typeof OrderSchema>; // TypeScript type from schema, free (replaces the hand-written interface)
const response = await fetch('/api/orders/123');
const data = OrderSchema.parse(await response.json());
// data is fully typed AND validated, bad shapes crash loudly at the boundary
You get full TypeScript inference for free via z.infer, and any malformed API response fails loudly at the entry point rather than corrupting data silently three function calls deep.
The four gates at a glance
Run through the gates in this order when setting up a new vibe-coded project:
- Write the interface or type before you write the prompt, so the AI has a contract to satisfy.
- Turn on
strict: trueplusnoUncheckedIndexedAccessandexactOptionalPropertyTypesin tsconfig, one-time setup. - Add typescript-eslint's
strict-type-checkedruleset to blockany, non-null assertions, and unsafe assignments. - Wrap every external data boundary, fetch responses, localStorage, URL params, in a Zod schema.
| Gate | Catches | Setup time |
|---|---|---|
| Types before prompts | Wrong data shapes, guessed property names | Per feature |
| Minimum tsconfig (strict, noUncheckedIndexedAccess) | Null derefs, unsafe array access, bad optional props | One-time |
| typescript-eslint strict-type-checked | any, non-null assertions, unsafe assignments | One-time |
| Zod at runtime boundaries | Malformed API responses at the entry point | Per external data source |
A fifth gate: AI code review
Type-level gates catch type errors before they ship, and the four above do that job well, but they don't catch everything, and the volume isn't shrinking. GitHub's Octoverse report says 80% of new developers on GitHub use Copilot in their first week. That's a lot of code passing through a reviewer who may only skim it.
When 80 percent of new developers on GitHub use Copilot in their first week, a fifth gate, dedicated AI code review on top of type checking, starts earning its place in serious pipelines.
That layer sits alongside TypeScript and ESLint, not in place of them. Tools like CodeRabbit, whose pricing page lists static analysis, secrets, dependency and infrastructure checks in its security review, flag security issues, logic gaps, and inconsistencies that a type checker was never built to catch, injection risks, leaked credentials, or a function that compiles cleanly but contradicts the ticket it was supposed to close. Think of it as gate five: types before prompts, strict tsconfig, typescript-eslint, Zod at the boundary, and then an AI reviewer scanning the diff before a human signs off.
One thing hasn't changed, though, and I'd argue it's the most important part of this whole framework: don't let AI be the only reviewer of AI-written code. Teams leaning hard into vibe coding actually need a stronger human review gate, not a weaker one, because the volume of code moving through the pipeline went up. A CI check that flags any and a bot that flags a suspicious diff both reduce risk. Neither replaces a human asking "does this actually do what we needed?"
Compounding quality
Compounding quality is the effect where each well-typed project produces reusable type definitions and habits that make the next project faster and safer, rather than every project starting from zero. Write types first, generate code second, let TypeScript and ESLint check the output. That's the whole framework.
Is it slower than pure vibe coding? Up front, a little: writing the type definitions for a feature is minutes of work, not hours. What you skip is the production debugging session two weeks later. The friction moves forward, closer to where you can actually fix things cheaply.
Each project you build with this framework produces reusable type definitions that speed up the next project. AI generates better code when you feed it well-typed context. And you build the habit of thinking about data shapes before implementations, which makes you a better reviewer of AI output.
For the deeper connection between TypeScript types and AI assistant quality, how well-typed context measurably improves Copilot and Claude Code output, see TypeScript types for AI.