Repository navigation
refactor(markdown-toolkit): check for arrays with assertIsArray - #198
Merged
Merged
Conversation
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[]`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Eight checks that a caller's value is an array now call one assert,
assertIsArray, in place of eight separateif … throwlines. Callers see the sameTypeErrorand 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 rowhtmlTable: the header, the rows and each rowdl: the entrieslist: the entriesSix test rows removed.
table.test.tsandhtmlBlocks.test.tseach 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.
listusedArray.isArray, which narrowed its entries toany[]. With the assert, the entries keep their real type, and that exposedlistItemNodedeclaring a narrower parameter than theAnyContent[]it passes straight on. Its parameter type now saysAnyContent[]. Only the type changed.