From ac0e372474b38dc8dfea661d230c1a61094564a2 Mon Sep 17 00:00:00 2001 From: Vance Ingalls Date: Sat, 8 Aug 2026 12:48:43 -0700 Subject: [PATCH] refactor: drop the non-null assertion and two casts the guards already cover MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three violations of the repo's "avoid `any`/`as T`" rule and the standing no-`!` rule, all in the carve's analysis path. `resolveAutomationRange` cast to `HfAudioFxNumberParam` immediately after `if (!param || param.kind !== "number") return null` — the discriminated union was already narrowed, so the cast asserted what the compiler knew. Removing it leaves tsc clean, which is the proof it was dead. `analyse` read `doc!.baseURI` and `el.getAttribute("src")!`, and laundered `getElementById`'s `HTMLElement | null` through `as HTMLAudioElement | null` into a predicate that only checked for a `src` attribute — so the "is this an audio element" claim was never actually tested by anything. The document is now guarded once at the top, and the voices are read out to `{ src, start }` values as they are found, which makes both fields non-null by construction rather than by assertion. The element check is by `tagName`, not `instanceof HTMLAudioElement`: these elements belong to the composition's iframe document, so this realm's constructor never matches them. It is not a narrowing either — `sourceOptions` is built from `doc.querySelectorAll("audio[id]")`, so a carve source is an `