Skip to content

Will the Type Checker Catch It?

Run the Will the Type Checker Catch It? MicroSim Fullscreen

About This MicroSim

The type checker reads your code and reports any place where a value is used in a way its type doesn't allow. It is quick and free. It also has limits that surprise many builders.

This MicroSim shows the CheckStatus type from the chapter and ten mistake cards. For each card you predict whether npx tsc --noEmit would catch it. Then you see the answer, the reason, and, for caught mistakes, a one-line error in the style of a tsc message.

Card 1 is the chapter's own example. Cards 2 to 10 are illustrative mistakes of the same kinds. Watch cards 1 and 5: they hold the same misspelling, one in code and one in a vendor's reply.

How to Use

  1. Read the type at the top and the mistake on the card.
  2. Press Caught by type checking or Not caught. Your first choice counts.
  3. Read the feedback, then press Next card.
  4. Hover the numbered dots to see each card and how you did.
  5. After card 10 you see your score and the cards you missed. Start over resets everything.

Iframe Embed Code

You can add this MicroSim to any web page by adding this to your HTML:

<iframe src="https://arunbatchu.github.io/good-enough-engineering/sims/type-checker-catch-it/main.html"
        height="524px"
        width="100%"
        scrolling="no"></iframe>

Lesson Plan

Learning Objective

Classify ten mistakes in a TypeScript app as caught or not caught by type checking, with at least eight of ten correct on the first attempt.

Grade Level

Adult professional (Good Enough Engineering)

Duration

10-15 minutes

Prerequisites

TypeScript, types, type checking, the CheckStatus type with three values, and the fact that Vite does not check types (all from Chapter 3).

Activities

  1. Exploration (3 min): Read the type and the first card. Predict before you look.
  2. Guided Practice (7 min): Work through all ten cards. After each one, say the rule in your own words: does the mistake live in the code, or in data that arrives while the app runs?
  3. Assessment (5 min): Compare cards 1 and 5. Explain to a partner why the same typo is caught in one place and not the other.

Assessment

Eight of ten correct on the first attempt shows mastery. A learner should also be able to say why a mistake in vendor data or in logic with valid types gets past the type checker, and why running only npm run dev with Vite never reports type errors.

References

  1. TypeScript Handbook: Everyday Types - TypeScript team. Union types like "pass" | "fail" | "not_checked".
  2. TypeScript: tsc CLI Options - TypeScript team. Includes --noEmit.
  3. Vite Features: TypeScript - Vite team. Vite transpiles TypeScript without type checking.
  4. Chapter 3: The Code Under Your App - this book. The Type Checking section.