Skip to content

Mechanical sweep: prefer plain 'as X' over 'as unknown as X' where the compiler allows it #5

Description

@DennisSmolek

What

A sweep of the corpus's 97 as unknown as sites found several documented-legitimate casts
(real @types/three gaps: PassNode.options — B11, BloomNode.highPassFn — B24,
Points.count — B34) that typecheck fine with the unknown intermediate hop dropped — a
plain as { options: … } / as ReturnType<typeof …> compiles clean, because the target
type still overlaps the source closely enough for TS's single-step assertion rule.

The double-hop form isn't wrong (it's the maximally-permissive form and never fails), but
it's stronger than the gap requires and reads as "TS is fighting me here" when a lighter
cast would do. One family (the backgroundNode/fogNode/environmentNode sites) was
already fully removed in an earlier sweep because @types/three closed that gap entirely.
This issue is about the remaining ~10 files' worth of double-hop casts that are still
necessary but could be single-hop.

Why it matters

Corpus-wide in reach but cosmetic — no correctness or behavior change, purely how tightly
each cast is scoped. Worth doing as a deliberate, verifiable pass (test each site with
as X, keep as unknown as X only where the compiler still demands it) rather than
mixed into an unrelated task, since verifying ~10 sites individually against tsc is
exactly mechanical-but-not-zero-risk enough to want its own PR and diff.

Recommendation already on file

docs/REVIEW-QUEUE.md #16: worth doing in the same pass as whatever normalizes the B11
comment wording, not as a rushed follow-up to a task whose ask was "remove the unnecessary
ones" rather than "minimize the necessary ones."

Pointer

docs/REVIEW-QUEUE.md §16 ("as unknown as X vs plain as X — should the corpus prefer
the minimal cast?").

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions