Skip to content

refactor(markdown-toolkit): check for arrays with assertIsArray - #198

Merged
Jason3S merged 1 commit into
mainfrom
claude/md-assert-is-array
Nov 11, 2026
Merged

Jason3S merged 1 commit into
mainfrom
claude/md-assert-is-array

Conversation

@Jason3S

@Jason3S Jason3S commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Eight checks that a caller's value is an array now call one assert, assertIsArray, in place of eight separate if … throw lines. Callers see the same TypeError and message as before. No behavior changes.

Changes

A new assert, assertIsArray(value, what). It throws <what> must be an array, got <what was given> and narrows the value to an array. It has its own tests.

Eight checks replaced.

  • table: the header, the rows and each row
  • htmlTable: the header, the rows and each row
  • dl: the entries
  • list: the entries

Six test rows removed. table.test.ts and htmlBlocks.test.ts each pinned the same three messages. The assert's own test covers the condition, the error class and the message form once.

A type the old check hid. list used Array.isArray, which narrowed its entries to any[]. With the assert, the entries keep their real type, and that exposed listItemNode declaring a narrower parameter than the AnyContent[] it passes straight on. Its parameter type now says AnyContent[]. Only the type changed.

Eight places checked that a caller's value is an array, each with its
own `if` and `throw`. They now call `assertIsArray`, which states the
expectation in one line and throws the same TypeError and message.

The assert is tested once, so the six test rows that pinned the same
message for `table` and `htmlTable` are removed.

`list` used `Array.isArray`, which narrowed its entries to `any[]` and
hid a mismatch: `listItemNode` declared a narrower parameter than the
`AnyContent[]` it passes on. Its parameter now says `AnyContent[]`.
@Jason3S
Jason3S merged commit a565d33 into main Nov 11, 2026
8 checks passed
@Jason3S
Jason3S deleted the claude/md-assert-is-array branch November 11, 2026 07:27
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.

1 participant