Skip to content

v0.2.5

Choose a tag to compare

@github-actions github-actions released this 28 Aug 17:00
· 42 commits to main since this release

Narrow instead of asserting, in the runtime's type guards

Eight checks were spelled typeof (x as { then?: unknown }).then === "function" — a cast whose only job was to reach a property, on a value
the surrounding condition had often only proven truthy. in narrows, so
nothing has to be asserted, and the cast was hiding that the guard did
not actually establish the value was an object.

The thenable check appeared four times and is now written once. So is
the length check, which was two casts on the same line: one to test the
property, one to read it.

Both accept a function as well as an object, because a thenable function
is legal and the checks they replace accepted one. hasLength also
accepts a string, which is neither — toHaveLength("abc", 3) caught
that when the first version narrowed too far.


Changes since v0.2.4.