Skip to content

enable noUncheckedIndexedAccess and resolve the resulting errors #39

Description

@vpmedia

What. noUncheckedIndexedAccess is the one compiler flag @vpmedia/phaser
still lacks that its siblings @vpmedia/bitcharify and @vpmedia/simplify
already hold. Enabling it reports 177 errors.

Why. Every remaining unchecked index read is a place where an out-of-range
lookup yields undefined and the code carries on with it. The rest of the
strictness work landed in 8efcb9a, 8f747a1 and 6dcfb35; this is the last
gap.

Why it was deferred. The 177 sites concentrate in the render, particle,
tween and earcut inner loops, where a per-element undefined guard is both a
per-frame runtime cost and noise in the hottest code in the library. That
trade-off deserves its own review rather than riding along with a release that
already changes the public nullability surface.

Prompt:

Enable noUncheckedIndexedAccess in tsconfig.json and resolve the 177 errors.

- Work file by file: `npx tsc --noEmit --noUncheckedIndexedAccess`.
- Prefer iterating the collection directly (`for...of`, `map`) over indexing;
  that removes the error rather than suppressing it, and reads better.
- Where the index is provably in range and the loop is per-frame hot, hoist the
  element into a local and guard once, rather than re-reading the index.
- Do not reach for `as` or `!` to silence a read. If a hot path genuinely cannot
  afford the check, say so in the PR and leave that file for a follow-up rather
  than asserting past it.
- Acceptance: `pnpm typecheck`, `pnpm lint`, `pnpm test` and `pnpm build` clean;
  bundle size not materially larger than the 646 kB the flag-free build produces.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions