Public code review lab
Why does a TypeScript default erase an explicit false?
Published
Published by Unrust. Scoring and editorial method
Quick answer
A type annotation does not change JavaScript evaluation. The || operator chooses the fallback when the left operand is falsy, which includes false. The ?? operator uses its fallback only for null or undefined, so it preserves false. Under this declared input type, omission produces undefined and therefore defaults to true.
Read the contract before the patch
The optional showHints boolean defaults to true when omitted. An explicitly supplied false must remain false. Inputs are assumed to satisfy the TypeScript type.
Predict the result before reading the repair. Use a small counterexample to separate the code’s behavior from the behavior you expected.
function showHints(options: { showHints?: boolean }): boolean {
return options.showHints || true;
}Compare the repair against the same inputs
A type annotation does not change JavaScript evaluation. The || operator chooses the fallback when the left operand is falsy, which includes false. The ?? operator uses its fallback only for null or undefined, so it preserves false. Under this declared input type, omission produces undefined and therefore defaults to true.
function showHints(options: { showHints?: boolean }): boolean {
return options.showHints ?? true;
}| Input | Original | Repair |
|---|---|---|
| { showHints: false } | true | false |
| { showHints: true } | true | true |
| {} | true | true |
Extend the review
TypeScript types do not validate untrusted JSON at runtime. Add boundary validation when an input may contain values outside the declared boolean type.
Change one assumption, predict a new outcome, then run the example in your own environment. The public lab repository contains the snippets and their checks. These examples teach review reasoning; they do not measure coding ability.
Interactive reasoning check
Make your prediction
Read the reasoning without answering
A type annotation does not change JavaScript evaluation. The || operator chooses the fallback when the left operand is falsy, which includes false. The ?? operator uses its fallback only for null or undefined, so it preserves false. Under this declared input type, omission produces undefined and therefore defaults to true.
A small practice loop
- 01State the input contract in your own words.
- 02Predict each boundary result before running the code.
- 03Compare the original and repair with exactly the same input.
- 04Write one additional case and explain what it establishes.
Common questions
Is this a scored Unrust assessment?
No. This is a fully public, worked teaching example. Its answers are intentionally available and it produces no diagnostic score.
Can I reuse the example in a tutorial?
Yes. The public lab source is MIT licensed. Keep the license, state the input contract and link to the example and its verification date.
Limits of this guide
TypeScript types do not validate untrusted JSON at runtime. Add boundary validation when an input may contain values outside the declared boolean type.
Sources and scope
Original public teaching material authored for Unrust and execution-checked on 21 October 2026. It is separate from the diagnostic and Daily puzzle banks.
- Nullish coalescing in TypeScript 3.7
TypeScript documentation
Nullish coalescing falls back for null or undefined instead of all falsy values.
Check your own starting point
Unrust uses short, timed, unassisted drills to give developers a per-skill snapshot. One session cannot explain the cause of a result, but it can show you what is worth practicing next.
Take the free diagnostic