Skip to content

Implement an explicit error message#189

Open
charpeni wants to merge 1 commit into
mmkal:mainfrom
charpeni:explicit-error-message
Open

Implement an explicit error message#189
charpeni wants to merge 1 commit into
mmkal:mainfrom
charpeni:explicit-error-message

Conversation

@charpeni
Copy link
Copy Markdown
Contributor

@charpeni charpeni commented Dec 9, 2025

Summary

Improve error messages for toBeAny(), toBeString(), toBeNumber(), and other type assertion methods to clearly show expected vs actual types

Fixes #179

Before

error TS2349: This expression is not callable.
  Type 'ExpectAny<2>' has no call signatures.

After

error TS2349: This expression is not callable.
  Type '{ "Expected: any, Actual: literal number: 2": never; }' has no call signatures.

For negated assertions:

error TS2349: This expression is not callable.
  Type '{ ".not.toBeAny() failed; Actual: any": never; }' has no call signatures.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Dec 9, 2025

Open in StackBlitz

npm i https://pkg.pr.new/mmkal/expect-type@189

commit: 66decd2

@charpeni charpeni force-pushed the explicit-error-message branch from eaa895b to 66decd2 Compare December 9, 2025 01:00
@charpeni charpeni marked this pull request as ready for review December 9, 2025 01:02
@mmkal
Copy link
Copy Markdown
Owner

mmkal commented Dec 9, 2025

I'm not against this - these messages are probably less intimidating for people who aren't yet familiar. Some feedback for this PR to be complete (though I'll still want to think about whether this is definitely better and also whether it should be considered a breaking change):

  1. Could you find the parts of the documentation that specifically reference the Type 'ExpectString<number>' has no call signatures kind of messages (bonus: see if there's some similar documentation in vitest?)
  2. We now have several types (like ExpectString) that are not used, I believe. If so, these should be removed. Once we can see what removing them looks like we can consider whether this would be a breaking change. (Probably not, as it's documented under "Internal Type Helpers" that these types might be removed without a major bump)

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.

toBeAny - confusing fail message

2 participants