0Pricing
TypeScript Academy · Lesson

Strictness flags

Turn on strictness for safer code: strict, noImplicitAny, exactOptionalPropertyTypes, noUncheckedIndexedAccess.

Strictness flags is a free TypeScript Academy lesson on CoddyKit — lesson 1 of 3. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, one of 3 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Intro

Goal: Enable and understand core strictness flags. These options push errors earlier and improve IDE hints.

  • strict
  • noImplicitAny
  • exactOptionalPropertyTypes
  • noUncheckedIndexedAccess

strict + noImplicitAny

strict flips on a bundle of checks; noImplicitAny forbids untyped parameters/vars that default to any.

// tsconfig.json (excerpt)
{
  "compilerOptions": {
    "strict": true,
    "noImplicitAny": true
  }
}

// Effect demo
function sum(a, b) { // Error: implicit any
  return a + b;
}

function sumOk(a: number, b: number): number {
  return a + b;
}

exactOptionalPropertyTypes

exactOptionalPropertyTypes distinguishes absent vs present but undefined—great for API modeling.

// exactOptionalPropertyTypes: true
interface User { name?: string }

const u1: User = {};          // ok: name is absent
const u2: User = { name: undefined }; // Error when exactOptionalPropertyTypes is true

function greet(u: User) {
  if ("name" in u) {
    // name exists but could be undefined without this flag
    console.log("Hi", u.name);
  }
}

Indexed access (array)

Indexing arrays now yields T | undefined. Check before using the value to avoid runtime crashes.

// noUncheckedIndexedAccess: true
const xs: number[] = [1,2,3];
const maybe = xs[5]; // type: number | undefined
if (maybe !== undefined) {
  console.log(maybe.toFixed(0));
}

Indexed access (map)

Objects and Record<K,V> index results include undefined until you prove presence.

// Also affects records/maps
const byId: Record<string, { id: string }> = {};
const item = byId["x"]; // { id: string } | undefined
if (item) {
  console.log(item.id);
}

Strict preset

Start strict and relax only if needed. These flags prevent common bugs with minimal noise in new code.

// tsconfig.json (excerpt)
{
  "compilerOptions": {
    "strict": true,
    "noImplicitAny": true,
    "exactOptionalPropertyTypes": true,
    "noUncheckedIndexedAccess": true
  }
}

Indexed access check

Quick check: What does noUncheckedIndexedAccess change?

Recap

Recap: strict enables safer defaults; noImplicitAny finds missing types; exactOptionalPropertyTypes models optional fields precisely; noUncheckedIndexedAccess forces presence checks.

Frequently asked questions

Is the “Strictness flags” lesson free?

Yes — the full text of “Strictness flags” is free to read here on the web, and the TypeScript Academy course includes 3 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO.

What will I learn in “Strictness flags”?

Turn on strictness for safer code: strict, noImplicitAny, exactOptionalPropertyTypes, noUncheckedIndexedAccess. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start TypeScript Academy?

No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 3, so you can start here or from the beginning and move at your own pace.

How long does the “Strictness flags” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this TypeScript Academy lesson?

Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Strictness flags
  2. Target, lib, module, JSX settings
  3. Project References (intro)
← Back to TypeScript Academy