Page type-check: strict throughout, a typed $, null checks (#236)
$<T> returns the element type it is given and assumes the element is there: 122 lookups take their type from the tag their id is on in the markup. A handler reads its target through a cast, since a typed element will not take a handler whose event names a narrower target. strictNullChecks found no bug the page had; its 94 places were values the code already handles in ways the type-check could not follow (data- attributes the page writes, a map entry set the line before, Share drawn only for an item with a link), each now said so. isPlayable stays a plain boolean: as a type guard its false would have meant "no file", and it is also false for a file that is not audio or video. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -154,9 +154,11 @@ node tests/page-smoke.js
|
||||
node --test tests/page-unit.js
|
||||
```
|
||||
|
||||
The first type-checks `web/src`: every parameter and variable has a type, and what the API sends
|
||||
is typed in `web/src/types.ts`, which mirrors the Rust structs and changes with them. Not yet
|
||||
null-safe: `strictNullChecks` is off and `$` returns `any` (#236). The second
|
||||
The first type-checks `web/src` in TypeScript's `strict` mode: every parameter and variable has a
|
||||
type, what the API sends is typed in `web/src/types.ts`, which mirrors the Rust structs and changes
|
||||
with them, and a value that may be null has to be checked before use. `$<T>` returns the element
|
||||
type it is given (`$<HTMLInputElement>('#nurl')`) and assumes the element is there; one that may
|
||||
not be is written `$(...)?.`, and the page check below proves the ones wired at load exist. The second
|
||||
builds the page as shipped and runs its script against a stub DOM, checking every selector it
|
||||
wires at load actually exists. That check exists because a patch once anchored on a deleted
|
||||
function, `String.replace` silently matched nothing, and the whole UI died with a
|
||||
|
||||
Reference in New Issue
Block a user