Skip to content

Update chapter 03's closure and predicate rules to TypeScript 5.4/5.5, and tidy chapter 02 - #18

Merged
renrenmimi merged 2 commits into
masterfrom
fix/content-functions-narrowing
Oct 10, 2026
Merged

renrenmimi merged 2 commits into
masterfrom
fix/content-functions-narrowing

Conversation

@renrenmimi

Copy link
Copy Markdown
Owner

Branches from #9 (commit 2148ad8), so it can be merged before or after it, and independently of #10–#17.

It touches chapter 02 (app/functions/page.tsx, viz.tsx, lib/functions-data.tsx) and chapter 03 (app/narrowing/page.tsx, viz.tsx, lib/narrowing-data.tsx). It does not touch the three ORDER_* presets, which #14 owns.

Summary

Fixes from the 2026-10-09 content audit (04-TSer-内容.md):

  • B3 (high)
    • What the chapter taught: a callback keeps narrowing only if the variable is "never reassigned anywhere in the function". This applied to the code note, the callout, the key point and the quiz.
    • Why that is wrong: it is the TypeScript 5.3 rule. Since 5.4, a callback created after the last assignment keeps the narrowing.
  • B6: inferred type predicates (TS 5.5) were described as working "only for a short callback with one parameter". In fact a block-bodied declaration and a two-parameter arrow both get o is Paid.
  • B12:
    • The claim: "TypeScript never adds behavior to the output. Type erasure is absolute." / 「类型擦除是铁律」.
    • Where it conflicts: chapter 08 teaches parameter properties, which do generate code.
  • B15: "typeof never throws" is false for a let or const in its temporal dead zone.
  • B23 (the ! operator): ! was called "a TypeScript annotation", while the term non-null assertion appeared only in the quiz.
  • B21 (quiz titles): the quiz titles used 通关测验.
  • B22 (register): colloquial Chinese, including 坑人, 一声不吭, 一刀切, 老老实实, 一场被夸大的战争, 吃的就是 and 挺过.
  • A26 (these chapters): the signature segments, the guard cells and the order-status buttons did not expose their selected state.

Changes

  • Chapter 03
    • Code note, callout and key point: they state the TS 5.4 rule. A callback keeps outside narrowing only if the variable is not assigned again after the callback is created.
    • Quiz: the question now places x = 42 after the if, at the end of the function, and every explanation follows the 5.4 rule.
    • Inferred predicates: the note and the task solution list the real conditions: no return type annotation, a single return, the parameter not modified, and true exactly when narrowed.
    • typeof: the explanation mentions the temporal dead zone.
    • !: it is introduced as 非空断言(non-null assertion).
  • Chapter 02: the readonly explanation now says readonly is erased like every type annotation and adds no code.
  • Both chapters: formal Chinese, 本章测验 / Chapter quiz, and aria-pressed on .fn-sig-seg, .nr-gx-cell and .nr-os-btn.

Verification

  • npx tsc --noEmit --incremental false: clean.
  • npm test: 6 files, 38 tests pass, including zh-copy-spacing.
  • npm run build: succeeds.
  • Rules checked with the lab worker on TypeScript 5.9.3 (during the audit):
    • An assignment before the callback gives no error.
    • The page's example, with value = 42 after the callback, reports TS2339 on string | number.
    • A function isPaidDecl(o) { const ok = …; return ok; } declaration and a (o, i) => … arrow are both inferred as o is Paid.
    • Two returns, or a non-iff test, give boolean.
    • typeof on a let before its declaration throws ReferenceError in Node 22.
  • Headless Chrome against a local next start, both languages:
    • The new text is on the page, the old rule statements are gone, and there are 0 console errors.
    • Two of the new strings sit in wrong-answer explanations that appear only after a quiz answer. They were checked in the source.

🤖 Generated with Claude Code

renrenmimi and others added 2 commits October 9, 2026 16:07
JSX trims each line of a text block and joins the lines with one space.
The Chinese copy is wrapped across source lines throughout the course, so
it rendered with spaces between Chinese characters and around full-width
punctuation: 1,572 of them in 36 files.

- 1,548 line breaks are joined by a script that walks the TypeScript
  syntax tree and touches only JSX text and JSX attribute strings, never
  code samples, template literals or comments. Breaks next to Latin
  letters, digits, expressions, "——" or operators keep their space.
- 24 more spaces go: 20 after full-width punctuation, 3 between Chinese
  text and a tag whose text is Chinese, and one {" "} between a
  full-width mark and Chinese text.
- test/zh-copy-spacing.test.ts, the check DataData and AlgoAlgo use,
  scans every TSX file and fails on any new stray space; CLAUDE.md states
  the rule.

Apart from the one {" "}, the diff changes nothing but whitespace. The
text every edited file renders differs from master only by deleted
spaces, each next to Chinese text, so the English copy is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…; tidy chapter 02

Chapter 03
- Narrowing in callbacks follows TypeScript 5.4: a callback keeps outside narrowing when
  it is created after the variable's last assignment. The code note, the callout, the key
  point and the quiz no longer teach "never reassigned anywhere in the function"; the quiz
  now says where x = 42 is written, and its explanations match the rule.
- Inferred type predicates (TS 5.5) are described by their real conditions: no return type,
  one return statement, the parameter not modified, true exactly when narrowed. Arrow
  functions and declarations with one parameter or several qualify.
- typeof does throw in the temporal dead zone; ! is introduced as the non-null assertion,
  not an annotation.

Chapter 02
- The readonly quiz explanation no longer claims that TypeScript never adds anything to the
  output (chapter 08 shows parameter properties that do); it says readonly is erased like
  every type annotation.

Both chapters
- Formal Chinese register (no 坑, 一声不吭, 一刀切, 老老实实, 一场被夸大的战争 and the
  like), quiz titles 本章测验 / Chapter quiz, and aria-pressed on the selectable buttons of
  the signature, guards and order-status visuals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 10, 2026 05:48
@vercel

vercel Bot commented Oct 10, 2026

Copy link
Copy Markdown

Deployment failed for project tser with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/renrenmimis-projects?upgradeToPro=build-rate-limit

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@renrenmimi
renrenmimi merged commit b332735 into master Oct 10, 2026
1 of 2 checks passed
@renrenmimi
renrenmimi deleted the fix/content-functions-narrowing branch October 10, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants