Skip to content

Remove spurious non-null assertions in createRegistry seek() #281

@johnleider

Description

@johnleider

createRegistry's seek() has two non-null assertions that are unnecessary and can be deleted with no behavior change:

// packages/0/src/composables/createRegistry/index.ts (in seek())
const ticket = tickets[i]!   // x2 — in the 'last' and 'first' loops

Why they're spurious

  • tickets is the result of values(), typed readonly E[].
  • packages/0 extends @vue/tsconfig/tsconfig.dom.json → base tsconfig.json, neither of which enables noUncheckedIndexedAccess (only tsconfig.lib.json does, and dom doesn't extend it). So tickets[i] is already typed E, not E | undefined.
  • The loops are also bounded (i >= 0 and i < tickets.length), so the index is always in range regardless.

Fix

Drop the ! on both tickets[i]! occurrences in seek(). Pure type-level cleanup — tickets[i] already has type E.

Notes

  • Surfaced while reviewing perf(createRegistry): replace Map-rebuild move with order-array splice + windowed reindex #273 (which removed every other ! from this file by storing ticket refs in the order array); these two live in seek() and were left out of scope there.
  • These are the last spurious ! in createRegistry/index.ts. The remaining assertions elsewhere in the file (listeners.get(event)!, get(id)! in the duplicate-register branch) are genuine Map.get bangs that document an invariant the type system can't see — leave those.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions