Skip to content

No. 47TypeScript8 min read2,201 words

Is strict TypeScript worth it? Flags, costs and rollout

Is strict TypeScript worth it? What each strict flag does, where the friction is real, and how to enable strict mode on an existing codebase without a bad week.

Written by
Lazy Devs
Published
Updated
Sources
Cited inline

Key takeaways ยท 05

The short version

  1. 01Yes for almost every codebase. strict: true turns on a family of checks, and strictNullChecks and noImplicitAny catch the bugs that matter most: missing values and silently untyped code.
  2. 02Strict types only describe your own code. Validate data at system boundaries, such as API responses, form input and environment variables, with a schema library like Zod, or strictness gives a false sense of safety.
  3. 03noUncheckedIndexedAccess is not part of strict but catches out-of-range array and record access. Enable it on new projects; consider it carefully on large existing ones.
  4. 04Turn strict on in an existing codebase incrementally: one flag at a time, or strict everywhere with existing errors suppressed by @ts-expect-error so only new code is held to the standard.
  5. 05Keep type errors fatal in CI and in next build. Setting ignoreBuildErrors permanently turns your types into decoration.
On this page ยท 10

Strict TypeScript is worth it on almost every codebase. Turning on "strict": true makes the compiler catch missing values and silently untyped code, which are the bugs that otherwise surface as Cannot read properties of undefined in production. The real cost is a bit of extra handling for values that might be absent, plus a rollout plan if you are retrofitting an existing project. The benefit is that you decide what happens when data is missing at compile time, before a user finds out for you.

Someone asks this on day one of nearly every project: do we turn on strict, or keep things loose so we can move fast? Our answer is to turn it on, but not for the reasons people usually give. It is not about purity. It is about which bugs you find in the editor and which ones you find at 2am.

What "strict" actually turns on

"strict": true is not one setting. It is a bundle of flags, and future TypeScript versions can add more to it.

FlagWhat it catchesDay-to-day value
strictNullChecksUsing a value that might be null or undefined without checkingVery high
noImplicitAnyVariables and parameters that silently became anyVery high
useUnknownInCatchVariablesTreating a caught error as a known type without checkingHigh
strictFunctionTypesUnsafe function parameter types in callbacksMedium
strictPropertyInitializationClass properties that are never assignedMedium, if you use classes
strictBindCallApplyWrong arguments to bind, call and applyLow, but free
noImplicitThisthis with an implicit any typeLow in modern code
alwaysStrictEmits "use strict" and parses in strict modeLow, but free
strictBuiltinIteratorReturnTreats built-in iterator return values as undefined rather than anyLow, but free

The two that earn their keep are strictNullChecks and noImplicitAny.

strictNullChecks

Without strictNullChecks, null and undefined are assignable to every type. That sounds convenient until you remember how many JavaScript crashes come from reading a property of something that turned out to be undefined.

type User = { id: string; name: string; email?: string };
 
function greeting(user: User): string {
  // Without strictNullChecks this compiles, then crashes when email is missing.
  return `Hi ${user.name}, we'll reach you at ${user.email.toLowerCase()}`;
  //                                             ~~~~~~~~~~ 'user.email' is possibly 'undefined'
}

With the flag on, that line does not compile. You are forced to write the branch you would have written after the bug report anyway:

function greeting(user: User): string {
  const email = user.email?.toLowerCase() ?? "no email on file";
  return `Hi ${user.name}, we'll reach you at ${email}`;
}

noImplicitAny

noImplicitAny flags any parameter or variable that silently became any because TypeScript could not infer a type. Silent any is how a typed codebase quietly rots: one untyped function argument switches off checking for everything downstream, and nobody notices because the editor stops complaining.

useUnknownInCatchVariables

With this flag, a caught error is unknown rather than any. That matches reality, since JavaScript lets you throw anything, and it forces you to narrow before reading .message:

try {
  await saveInvoice(invoice);
} catch (error) {
  const message = error instanceof Error ? error.message : String(error);
  logger.error("Saving invoice failed", { message });
}

Where the friction is real

Strict mode is not free. There are two places it costs real time, and naming them up front stops teams being blindsided.

Data at the boundary

TypeScript checks your code, not the JSON that comes back from an API. The types vanish at runtime. When you write await res.json(), you get any, and whatever type you assign to it is a promise you made, not a fact the compiler checked. Strict mode pushes the danger to your system boundaries, which is exactly where you want it. Validate there with a runtime schema library like Zod, and infer the type from the schema so the two cannot drift:

import { z } from "zod";
 
const UserSchema = z.object({
  id: z.string(),
  name: z.string(),
  email: z.string().email().optional(),
});
 
export type User = z.infer<typeof UserSchema>;
 
export async function fetchUser(id: string): Promise<User> {
  const res = await fetch(`/api/users/${id}`);
  if (!res.ok) throw new Error(`User fetch failed: ${res.status}`);
  // parse() throws on a bad shape, so everything after this point is truly typed
  return UserSchema.parse(await res.json());
}

The same applies to form input, query strings, webhook payloads and environment variables. Without boundary validation, strict mode gives a false sense of safety: your code is sound, but bad data walks straight past the type checker. We use the same pattern in Server Actions, as shown in our guide to Next.js authentication patterns.

Array and record access

The flag teams fight hardest is noUncheckedIndexedAccess, which is not part of strict. It makes arr[0] and record[key] return T | undefined instead of T, because indexing past the end of an array really does give you undefined, and TypeScript was not telling you before. It is correct, and it is also noisy in loops where you know the index is valid.

Our take: turn it on for new projects from the first commit, where the cost is low and it shapes good habits. On a large existing codebase, add it after the core strict flags are clean, or enable it for new modules first.

Beyond strict: the flags we add

Strict is the floor, not the ceiling. On new projects we usually add a few more:

FlagWhy we turn it on
noUncheckedIndexedAccessMissing array items and record keys become visible
exactOptionalPropertyTypesDistinguishes "property missing" from "property set to undefined"
noImplicitOverrideRequires override on subclass methods, so renames in a base class do not silently break subclasses
noFallthroughCasesInSwitchCatches accidental fall-through in switch statements

exactOptionalPropertyTypes is the most opinionated of these and can be painful with some libraries' types, so we treat it as optional.

Type-aware lint rules close gaps the compiler leaves open. The most valuable is typescript-eslint's no-floating-promises, which flags promises you forgot to await or handle, a classic source of silent failures.

Police the escape hatches

Strict mode only holds if the ways around it stay rare and visible. TypeScript gives you several, and each one is a place where the compiler stops checking and starts trusting you:

Escape hatchWhat it doesWhat we do instead
as SomeTypeTells the compiler a value has a type, without checkingValidate with a schema, or narrow with a type guard
Non-null assertion (value!)Claims a value is not null or undefinedHandle the missing case, or throw a clear error
Explicit anyTurns off checking for that value and everything it touchesUse unknown and narrow it
@ts-ignoreSilences the next line's error permanently@ts-expect-error with a comment explaining why

None of these are banned outright. A cast is sometimes the honest answer, for example when a library's types are wrong or a DOM API returns a broader type than you know you have. The rule we follow is that every escape hatch should be deliberate, local and explained in a comment, so a reviewer can tell a considered exception from a shortcut.

Two tools make that easy to enforce. typescript-eslint's no-explicit-any and no-non-null-assertion rules flag the most common shortcuts in review rather than in production. And the satisfies operator lets you check that a value matches a type without widening it, which removes many of the casts people write for configuration objects and lookup tables:

type Plan = "free" | "pro" | "team";
 
const limits = {
  free: 3,
  pro: 25,
  team: 100,
} satisfies Record<Plan, number>; // a missing or misspelled plan is an error

If the backlog of escape hatches grows faster than it shrinks, treat that as a signal: usually a boundary is not validated, or a shared type no longer matches the data it describes.

Strict types make other patterns better

Strictness pays off most when you design types to make invalid states impossible. A discriminated union for request state means "loading and errored at once" cannot be represented, and the compiler narrows each branch for you:

type Result<T> =
  | { status: "loading" }
  | { status: "error"; error: Error }
  | { status: "success"; data: T };

This shows up throughout our React work, from error handling patterns in React to how we model state in React state management. Without strictNullChecks, much of the narrowing that makes these patterns safe does not work.

The same logic extends across the network: typed API contracts are one of the reasons teams reach for GraphQL, which we weigh up in when GraphQL is the right call.

Common objections, answered

"It slows us down." At first, a little, mostly in the places where your code was quietly assuming a value exists. After a few weeks the habit is automatic, and the time comes back as fewer production bugs and safer refactors. Renaming a field in a strict codebase is a compiler-guided job; in a loose one it is a search-and-hope job.

"We have tests for that." Tests check the cases someone thought of. The type checker checks every path through the code on every save, including the branch where an optional field is missing that nobody wrote a test for. The two are complementary, and strict types let your tests focus on behaviour instead of shape.

"Our library's types are wrong." Sometimes they are. Fix it locally with a small typed wrapper or a module augmentation, and keep the escape hatch in one place rather than loosening the whole project.

"It is just a prototype." Prototypes have a habit of becoming the product. Strict mode costs least on day one, when there is no backlog of errors, and most when you try to add it a year later. For a founder, that is the real budget question: tightening types later is a project with its own cost, while starting strict is close to free. It is one of the cheapest ways to avoid the kind of technical debt that slows every later feature.

Turning it on without a bad week

The mistake teams make is flipping strict to true on a large codebase and staring at thousands of errors. That is how strict mode gets reverted by Friday. Roll it out deliberately instead.

Option 1: one flag at a time

  1. Enable noImplicitAny and fix or explicitly annotate what it finds. Explicit any is allowed; silent any is not.
  2. Enable strictNullChecks. These errors take real thought, because each one asks "what should happen when this is missing?"
  3. Enable strict to pick up the remaining, smaller flags.
  4. Add noUncheckedIndexedAccess and the extras once the codebase is clean.

Option 2: strict now, backlog suppressed

Enable everything, then run a script that inserts a // @ts-expect-error comment above every current error. New code is held to the standard immediately, and the old errors burn down as people touch each file.

// tsconfig.json
{
  "compilerOptions": {
    "strict": true,
    "noUncheckedIndexedAccess": true
  }
}

Use @ts-expect-error, not @ts-ignore. If someone later fixes the underlying issue, an unused @ts-expect-error becomes an error itself, so the codebase tells you when a suppression is no longer needed. Track the count in CI and make sure it only goes down.

For very large monorepos, project references let you hold different packages to different settings while you migrate them one by one. Our monorepo guide covers when that structure is worth it.

Keep the type check in the pipeline

Strict settings only matter if type errors block a release.

  • In Next.js, next build fails on type errors by default. The TypeScript config docs describe ignoreBuildErrors for special cases like migrations; do not leave it on permanently, or your project ships broken types on every release and nobody notices until the types are decorative. The typedRoutes option is also worth enabling: literal href values in next/link and router methods are checked against your real routes, so a link to a page that does not exist becomes a type error.
  • When running TypeScript directly, remember that tools which strip types to execute files quickly, including Node.js's built-in TypeScript support, do not type-check. Run tsc --noEmit in CI.
  • In CI generally, run the type check as its own step alongside tests, so failures are obvious. Our guide to CI/CD that small teams maintain shows where it fits.

So, is it worth it?

For a new project, yes, without hesitation. Turn on strict and noUncheckedIndexedAccess from the first commit, validate at your boundaries with a schema library, and spend your debugging time on actual logic.

For a large existing codebase, it is still worth it, but incrementally. Flip the flags in order or suppress the backlog, hold new code to the standard, and let the error count fall as the code evolves. The teams that regret strict mode are almost always the ones that tried to do it all in one pull request.

The value is not stricter types for their own sake. Strict mode forces you to decide, at compile time, what happens when data is missing or malformed. You were going to make those decisions anyway. Strict TypeScript makes you make them before a user does.

If you want strict, well-typed code from day one, or a safe plan to tighten an existing codebase, that is what our TypeScript development team does. Get in touch.

FAQ ยท 05 questions

Frequently asked questions

What does strict mode do in TypeScript?

Setting strict to true in tsconfig.json enables a family of stricter type-checking options at once, including noImplicitAny, strictNullChecks, strictFunctionTypes, strictBindCallApply, strictPropertyInitialization, noImplicitThis, useUnknownInCatchVariables, alwaysStrict and strictBuiltinIteratorReturn. New strict-family flags added in future TypeScript versions are included automatically, so upgrades can surface new errors.

Does strict TypeScript slow down development?

Slightly at first, mostly when handling values that might be null or undefined and when typing data from outside your code. In return you spend far less time debugging runtime crashes from missing values. On new projects the cost is small; on existing codebases it is manageable if you roll it out incrementally.

Should I use noUncheckedIndexedAccess?

On new projects, yes. It makes array and record lookups return a type that includes undefined, which matches what JavaScript actually does when an index or key is missing. On a large existing codebase it can produce a lot of noise, so enable it once the main strict flags are clean, or in new modules first.

Does strict TypeScript validate API responses?

No. TypeScript types disappear at runtime, so they cannot check data that arrives from a network request, a form or a file. Validate that data with a runtime schema library such as Zod at the point it enters your system, and infer the TypeScript type from the schema so the two never drift apart.

How do I enable strict mode on a large TypeScript codebase?

Enable flags one at a time, starting with noImplicitAny and then strictNullChecks, or enable strict globally and mark existing errors with @ts-expect-error comments so new code is checked immediately. Burn down the suppressions as you touch each file. Keep the type check in CI so the count only goes down.

Related service

TypeScript Development Services

End-to-end type safety, front end to back end.

Learn more

Next step

Want this built right?

This is the work we do every day. Tell us what you are building and we will show you exactly how we would ship it.

First reply
Within 1 business day
Typical start
1โ€“2 weeks
Pricing
Fixed price per phase
You own
All code and accounts