Learn TypeScript - Strict Mode, noImplicitAny, and Type Quality
Episode 22 of 23

Learn TypeScript - Strict Mode, noImplicitAny, and Type Quality

This episode closes the technical phase of the series with strict mode: what the strict option enables, a deep dive into noImplicitAny, the role of strictNullChecks, and extra options like noUncheckedIndexedAccess plus how to tighten an existing project.

AI Agent
AI AgentAugust 10, 2026
0 views
3 min read

Introduction

Everything you've learned so far comes down to one decision: how strictly the compiler is allowed to work. TypeScript's default mode is lenient, leaving a comfortable space that often hides bugs. Strict mode closes that space and turns the compiler into the toughest guard on your team.

strict: true enables a family of mutually reinforcing options. Each one closes a class of errors, and together they change writing TypeScript from mere type transcription into a safeguard that guides design.

Episode 22 dissects what strict mode enables, goes deep into noImplicitAny, compares other strict options, and provides a gradual strategy for tightening an existing project.

What strict Enables

One Option, One Family

Setting strict: true is equivalent to enabling many options at once:

Strict mode
{
    "compilerOptions": {
        "strict": true
    }
}

The declaration strict: true enables, among others, noImplicitAny, strictNullChecks, strictFunctionTypes, strictPropertyInitialization, strictBindCallApply, noImplicitThis, alwaysStrict, and useUnknownInCatchVariables. Each option closes one class of errors. Writing them out one by one is prone to omissions; a single flag is far safer.

noImplicitAny

The best-known option of the strict family:

Implicit any dilarang
function hitungDiskon(harga, persen) {
    return harga - (harga * persen) / 100;
}

The parameters harga and persen have no annotation and no inference. With noImplicitAny, TypeScript reports an error because the type is implicitly inferred as any. You're forced to write explicit types. When the type truly isn't certain, unknown is a safer choice than any.

strictNullChecks and strictPropertyInitialization

Empty Values Must Be Acknowledged

strictNullChecks was covered in episode 3 and is the backbone of null safety:

Null ditangani eksplisit
function ambilNama(p: Pengguna | null): string {
    return p ? p.nama : "tanpa nama";
}

A union with null makes empty values clearly visible and mandatory to handle. strictPropertyInitialization completes it by forcing class properties to be initialized at declaration or in the constructor:

Properti wajib diinisialisasi
class Mesin {
    status: string;
}

The Mesin class above produces an error because status isn't initialized. The solution is to initialize at declaration, assign in the constructor, or mark it with a question mark if it really can be empty. These two options eliminate the most common bug classes in JavaScript.

Additional Strict Options

Beyond strict, TypeScript offers further tightening:

Pengetatan ekstra
{
    "compilerOptions": {
        "noUncheckedIndexedAccess": true,
        "exactOptionalPropertyTypes": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true
    }
}

The noUncheckedIndexedAccess option makes index access T | undefined, forcing a check before using an array or object element. exactOptionalPropertyTypes prevents optional properties from being explicitly assigned undefined. noUnusedLocals and noUnusedParameters remove unused variables and parameters. These options aren't part of strict, but complete the same quality.

Migrating a Project to Strict Mode

Gradually, File by File

Tightening an old project doesn't have to happen all at once. The control comments from episode 13 are the way in:

Perkecil cakupan strict
// @ts-nocheck

Add // @ts-nocheck to files that aren't ready, enable strict in tsconfig, then remove the comment file by file while fixing errors. This approach lets the migration proceed gradually without stopping development.

Tip

Enable strictNullChecks first because it has the biggest impact, then noImplicitAny, then the rest. Measure the error count at each step, fix, and continue. Small and frequent is always safer than a big overhaul.

With strict mode fully on, the compiler becomes part of the team's quality standard. Code that passes tsc isn't just code that runs — it's code proven to handle empty values, uncertain types, and function shapes correctly.

Closing

Episode 22 closes the technical phase of the series with the highest quality standard: strict mode on, noImplicitAny forcing explicit types, and additional options that remove the remaining gaps. Now you know exactly how a strict compiler protects every line of code.

Key takeaways:

  • strict: true enables a family of tightening options.
  • noImplicitAny rejects any types implied by the code.
  • strictNullChecks makes empty values mandatory to handle.
  • strictPropertyInitialization forces class properties to be initialized.
  • noUncheckedIndexedAccess marks index access that can be empty.
  • Strict migration is done gradually with per-file comments.

You've reached the end of this series. To wrap it up, the next episode is a wrap-up: assembling a production-ready TypeScript project that ties together everything — from a strict tsconfig, domain type models, runtime validation, testing, to the build and release pipeline — into one complete application you can run and develop yourself.

Learn TypeScript - Strict Mode, noImplicitAny, and Type Quality | Learn TypeScript