TypeScript Strictness and Team Velocity: A Practical Guide

Which TypeScript compiler flags actually pay for themselves, how strictness changes refactors and onboarding, and a tsconfig we recommend as a starting point for new product codebases.

DIDatainter TeamNOV 15, 20258 MIN READTECHNOLOGY

Every team that adopts TypeScript eventually has the same argument. One engineer wants every strict flag turned on. Another says the compiler is slowing the team down and any is fine for now. Both are partly right, and the argument usually goes in circles because nobody measures what strictness costs or what it buys.

This article treats strictness as an engineering investment with a payback period. We will look at which flags matter, what they change about day-to-day work, how they interact with refactoring and onboarding, and what a sensible configuration looks like for a product team shipping weekly.

What “strict” actually means

The strict flag in tsconfig.json is a bundle. Turning it on enables a set of checks that the TypeScript team considers the baseline for sound code. The most important members are:

  • strictNullChecks: null and undefined are no longer silently assignable to every type. This single flag eliminates the largest class of runtime errors in JavaScript code, the dreaded “cannot read properties of undefined”.
  • noImplicitAny: variables and parameters whose type cannot be inferred must be annotated instead of silently becoming any.
  • strictFunctionTypes and strictBindCallApply: function parameter types are checked contravariantly, and bind, call and apply are typed properly.
  • strictPropertyInitialization: class properties must be assigned in the constructor or declared optional.
  • useUnknownInCatchVariables: caught errors are unknown, not any, so you must narrow before using them.
  • alwaysStrict: emits "use strict" in output.

Beyond the bundle, several flags are not included in strict but matter just as much in practice. We cover them later.

The key idea is that these flags are not equally valuable. strictNullChecks and noImplicitAny deliver most of the benefit. The rest are cheap refinements that rarely cause friction in new code.

The velocity argument, honestly

The case against strictness is real. In the first weeks of a project, strict typing slows you down. You write more annotations, you fight the compiler over narrowing, and prototypes take longer to reach the demo. If your product is a two-week experiment that you will throw away, loose settings are rational.

The case for strictness is about the other 95 percent of a codebase’s life. Consider where engineering time actually goes after the first month:

  • Reading code written by someone else, or by you three months ago.
  • Changing existing behavior without breaking unrelated features.
  • Debugging production issues that tests did not catch.
  • Reviewing pull requests.

Strict types accelerate all four. A function signature with string | null tells the reader and the reviewer something a signature returning any never will. The compiler becomes a reviewer that never gets tired.

Strictness is a loan you take out in week one and repay with interest every time someone changes the code in month eighteen.

A useful mental model is that strictness moves a bug’s discovery time from production, to CI, to the editor. Each step earlier is roughly an order of magnitude cheaper to fix. Teams that adopt strict mode at the start of a project typically report fewer production incidents of the “undefined is not an object” variety, and shorter code review cycles because reviewers stop asking “can this be null?”

Technology · TypeScript Strictness and Team Velocity: A Practical Guide

Refactoring: where strictness pays off most

The clearest return shows up in refactors. Suppose you rename a field on a core domain object, change the shape of an API response, or split one function into two. In a loosely typed codebase, you rely on search, tests, and hope. In a strict one, you change the type and follow the red squiggles.

Three patterns make this work particularly well.

Discriminated unions for state

Model states explicitly instead of using optional fields:

type LoadState =
  | { status: "idle" }
  | { status: "loading" }
  | { status: "success"; data: Invoice[] }
  | { status: "error"; error: Error };

When you add a new status, every switch statement that handles LoadState fails to compile if you include an exhaustiveness check:

function assertNever(x: never): never {
  throw new Error(`Unexpected value: ${JSON.stringify(x)}`);
}

This turns “did I update every place that handles this?” from a code review question into a compiler error.

Branded types for identifiers

Mixing up a UserId and an OrderId is a classic bug when both are strings. A branded type makes the compiler catch it:

type Brand<T, B> = T & { readonly __brand: B };
type UserId = Brand<string, "UserId">;
type OrderId = Brand<string, "OrderId">;

It costs a few lines and removes an entire category of silent data mix-ups, especially in financial or multi-tenant systems where passing the wrong ID is a security issue, not just a bug.

Validation at the boundary

Types are erased at runtime, so data entering the system from the network, a database or a queue is untrusted regardless of what you annotate. Use a schema library such as Zod or Valibot to parse inputs and infer the static type from the schema. Then strict mode protects everything inside the boundary, and the parser protects the boundary itself. Without this step, strict types give a false sense of safety.

Onboarding: types as living documentation

New engineers take weeks to become productive, and most of that time is spent building a mental model of the domain. Strict types speed this up in a measurable way.

  • Autocomplete becomes trustworthy. With any sprinkled through the code, completion silently stops working in the middle of a chain. With strict types, a new hire can explore an unfamiliar module by typing a dot.
  • Function signatures answer questions. “What does this return when the user has no subscription?” is answered by the return type, not by reading the body.
  • Mistakes surface privately. A junior engineer who gets a compiler error learns without the social cost of a failed review.

A practical onboarding tactic is to ask a new hire to fix a small ticket, then watch where they get stuck. If the answer is “I did not know this could be undefined”, the types are underspecified. If the answer is “I did not know which of these three similar functions to call”, the problem is naming, not types, and strictness will not save you.

Flags beyond strict worth enabling

Several options sit outside the bundle and are worth considering from day one.

Flag What it does Cost Recommendation
noUncheckedIndexedAccess Array and record index access returns T \| undefined Moderate; adds narrowing Enable for new projects
exactOptionalPropertyTypes Distinguishes missing from undefined Moderate; breaks some libraries Enable if you control most types
noImplicitOverride Requires override keyword Low Enable
noFallthroughCasesInSwitch Flags accidental fallthrough Low Enable
noUnusedLocals / noUnusedParameters Flags dead code Low, but noisy in editors Enable in CI, relax locally
verbatimModuleSyntax Forces explicit import type Low Enable
isolatedModules Ensures each file can be transpiled alone Low Required by most bundlers

noUncheckedIndexedAccess deserves a special mention. Without it, const first = items[0] has type Item even when items is empty. That is a lie the compiler tells you. With the flag enabled, you handle the empty case. It is the flag that most often finds real bugs in an otherwise strict codebase, and also the one that generates the most initial grumbling.

This is a reasonable starting point for a modern application targeting current runtimes and a bundler:

{
  "compilerOptions": {
    "target": "ES2022",
    "lib": ["ES2023", "DOM", "DOM.Iterable"],
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "strict": true,
    "noUncheckedIndexedAccess": true,
    "noImplicitOverride": true,
    "noFallthroughCasesInSwitch": true,
    "exactOptionalPropertyTypes": true,
    "verbatimModuleSyntax": true,
    "isolatedModules": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "noEmit": true
  },
  "include": ["src"]
}

A few notes. skipLibCheck is a pragmatic choice: it avoids type errors inside third-party declaration files you cannot fix. noEmit assumes your bundler or runtime handles compilation and you use tsc only for checking. For libraries you publish, you will also want declaration and a proper build step. Check the official TypeScript documentation for the current list of options, since defaults evolve between releases.

Migrating an existing codebase

Most teams do not get to start fresh. The temptation is to flip strict: true and face four thousand errors. Do not. A staged approach works better.

  1. Enable flags one at a time, starting with noImplicitAny, then strictNullChecks. Each flag gets its own pull request and its own error budget.
  2. Use a ratchet. Record the current error count per flag in CI and fail the build if it goes up. Tools such as typescript-strict-plugin or a simple script that runs tsc against a stricter config on changed files let you enforce strictness on new code only.
  3. Split by directory. Create a tsconfig.strict.json that extends the base config and includes only migrated folders. Grow the include list weekly.
  4. Ban new any with lint rules. The @typescript-eslint/no-explicit-any rule, combined with no-unsafe-assignment and its siblings, stops new debt while you pay down old debt.
  5. Prefer unknown to any. When you truly do not know a type, unknown forces a check before use.

Budget realistically. A mid-sized application of around 100,000 lines typically needs a few engineer-weeks spread over a quarter to reach full strictness, and it pays back in fewer regressions within the same period. Do it incrementally and the team never stops shipping features.

Escape hatches and how to govern them

Strict does not mean zero escape hatches. There are legitimate uses of as assertions, // @ts-expect-error, and non-null assertions (!). The goal is to make them visible and reviewed.

  • Prefer @ts-expect-error over @ts-ignore. The former fails when the error disappears, so stale suppressions are caught.
  • Require a comment explaining every assertion that narrows a type, and every !.
  • Treat double assertions such as as unknown as Foo as a code smell that needs a reviewer’s explicit sign-off.
  • Wrap unavoidable unsafe code in small, well-tested functions so the rest of the codebase stays sound.

Count your escape hatches periodically. A rising count is an early warning that the types no longer match how the team thinks about the domain.

Compile times and editor performance

One legitimate cost of strict, heavily inferred TypeScript is build and editor latency. Large codebases with complex conditional types can make tsc take minutes and the language server lag. Mitigations that work:

  • Use project references and incremental builds so only changed packages are rechecked.
  • Annotate return types of exported functions explicitly. This speeds up declaration emit and prevents accidentally leaking enormous inferred types.
  • Avoid deeply recursive conditional types in hot paths.
  • Run type checking as a separate CI step in parallel with tests, and let a fast transpiler such as esbuild or SWC handle bundling.

Measure with tsc --extendedDiagnostics before optimizing. Most slow projects have one or two pathological types, not a general problem.

Key takeaways

  • Enable strict from the first commit of a new project; the cost is hours at the start and the benefit compounds for the life of the codebase.
  • strictNullChecks and noImplicitAny deliver most of the value. Add noUncheckedIndexedAccess for the bugs that remain.
  • Use discriminated unions, branded identifiers and schema validation at boundaries so strict types reflect reality rather than hope.
  • For existing code, migrate flag by flag with a CI ratchet instead of a big-bang rewrite.
  • Govern escape hatches: prefer unknown, use @ts-expect-error, and track the count of assertions over time.
#typescript#tooling#developer experience#refactoring
DI
Datainter TeamEngineers, designers and operators building software and fintech products from Medellín, Tigard and Luxembourg.

Building something in this space?

Talk to the team that ships and operates it. We reply within one business day.

Start a project
Chat with us on WhatsAppUSUALLY REPLIES WITHIN MINUTES