Skip to content

Enable noUncheckedIndexedAccess with ArrayUtils.assertGet and StringUtils.assertGet#408

Merged
JordanBoltonMN merged 3 commits into
masterfrom
dev/jobolton/next
Jun 8, 2026
Merged

Enable noUncheckedIndexedAccess with ArrayUtils.assertGet and StringUtils.assertGet#408
JordanBoltonMN merged 3 commits into
masterfrom
dev/jobolton/next

Conversation

@JordanBoltonMN

@JordanBoltonMN JordanBoltonMN commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Enables noUncheckedIndexedAccess: true in tsconfig.json. All indexed array and string accesses are now explicitly checked at compile time, with runtime safety provided by dedicated assert helpers.

Changes

  • tsconfig.json: Added noUncheckedIndexedAccess: true
  • ArrayUtils.assertGet: Updated default error message/details to include index and collection length
  • StringUtils.assertGet: New helper for safe string character access with diagnostics
  • ~30 source and test files: Replaced raw indexed accesses with ArrayUtils.assertGet(arr, i) or StringUtils.assertGet(str, i)
  • Audited existing Assert.asDefined calls and migrated array-indexed ones to the new helpers

Rationale

noUncheckedIndexedAccess forces the compiler to treat every arr[i] as T | undefined, catching potential out-of-bounds bugs at compile time. The dedicated assertGet helpers provide:

  1. Runtime safety - throws InvariantError if the index is out of bounds
  2. Diagnosability - error messages include the index and collection/string length
  3. Readability - clearly communicates intent vs raw ! or Assert.asDefined

Adds
oUncheckedIndexedAccess: true to tsconfig.json and wraps all
indexed array/string accesses with Assert.asDefined() to satisfy the
stricter type checking. This provides runtime safety for all array
index accesses that were previously unchecked.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JordanBoltonMN JordanBoltonMN force-pushed the dev/jobolton/next branch 2 times, most recently from 971c939 to 7f1ed0f Compare June 8, 2026 19:10
…sertGet

Adds noUncheckedIndexedAccess: true to tsconfig.json and wraps all
indexed array accesses with ArrayUtils.assertGet() to satisfy the
stricter type checking. This provides runtime safety for all array
index accesses that were previously unchecked.

Updates ArrayUtils.assertGet to include a default error message and
details (index + collection length) for better diagnosability.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JordanBoltonMN JordanBoltonMN changed the title Enable noUncheckedIndexedAccess and fix all errors with Assert.asDefined Enable noUncheckedIndexedAccess with ArrayUtils.assertGet and StringUtils.assertGet Jun 8, 2026
@JordanBoltonMN JordanBoltonMN requested a review from mattmasson June 8, 2026 19:14
When lexing '..' at end of line, chr3 at positionStart+2 may not exist.
Use optional indexing instead of StringUtils.assertGet since the
character may legitimately be absent (DotDot vs Ellipsis lookahead).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JordanBoltonMN JordanBoltonMN merged commit b040172 into master Jun 8, 2026
5 checks passed
@JordanBoltonMN JordanBoltonMN deleted the dev/jobolton/next branch June 8, 2026 23:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants