Skip to content

chore: upgrade TSTyche #4745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 12, 2025
Merged

chore: upgrade TSTyche #4745

merged 11 commits into from
May 12, 2025

Conversation

mrazauskas
Copy link
Contributor

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

This PR upgrades TSTyche to version 4. (It is still in beta, because I plan to implement few more features and that will break programatic usage. Nothing breaking is planned for CLI usage.)

The highlight of TSTyche 4 are the ability matchers: .toBeCallableWith(), .toBeConstructableWith(), etc. Detailed release notes can be found here: https://tstyche.org/releases/tstyche-4

In this PR many // @ts-expect-error are replaced with .not.toBeCallableWith(). There are much more // @ts-expect-error still left around. I will handle them later. The idea was to show you what is possible and to ask for feedback. Also these tests were a great playground to try out new features.

How it Works?

Implementation of the ability matchers is somewhat similar to ts-blank-space. After retrieving diagnostics for a file, TSTyche creates a virtual copy of it with erased assertions and asks TypeScript for diagnostics again.

An assertion like this:

expect(Duration.decode).type.toBeCallableWith("10 unknown")

Becomes:

;     (Duration.decode)                      ("10 unknown")

Any found error are reported (or silenced if .not is included):

Screenshot 2025-04-15 at 14 52 27

Copy link

changeset-bot bot commented Apr 15, 2025

⚠️ No Changeset found

Latest commit: 41dea9a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Comment on lines -3 to -4
"checkSourceFiles": true,
"rejectAnyType": true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These now are enabled by default.

@mrazauskas mrazauskas marked this pull request as draft April 16, 2025 11:09
@gcanti
Copy link
Contributor

gcanti commented Apr 18, 2025

This is awesome, thanks for working on this @mrazauskas

Array.sort([1], Order.string)
// @ts-expect-error: wrong `Order` type
Array.sort(Order.string)([1])
when(pipe).isCalledWith([1], expect(Array.sort).type.not.toBeCallableWith(Order.string))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add the when() utility. As you see in this line, it is a helper that wraps an expression and allows calling it during the type test run. This allows passing expect() as an argument and test a callback as if it is an argument of the outer function.

Similar to .toBeCallableWith(), the implementation erases when(). The line above becomes:

;   (pipe)             ([1],       (Array.sort)                          (Order.string))

@mrazauskas mrazauskas marked this pull request as ready for review May 10, 2025 10:42
@mrazauskas
Copy link
Contributor Author

mrazauskas commented May 10, 2025

@gcanti Could you take a look, please.

There are only 31 instances of // @ts-expect-error left. These are either not related with callability or too complex to be covered now. This change is large enough. Perhaps it is worth to land it and to iterate.

If beta is an issue, I am ready to publish rc.

@gcanti
Copy link
Contributor

gcanti commented May 12, 2025

This change is large enough. Perhaps it is worth to land it and to iterate

agreed

If beta is an issue, I am ready to publish rc.

no problem, I'm fine with a beta, there's no rush, we are happy to help you out with the next release of tstyche

@gcanti gcanti merged commit ba7d7e0 into Effect-TS:main May 12, 2025
11 checks passed
@github-project-automation github-project-automation bot moved this from Discussion Ongoing to Done in PR Backlog May 12, 2025
@mrazauskas mrazauskas deleted the upgrade-tstyche branch May 12, 2025 10:28
@mrazauskas
Copy link
Contributor Author

Wonderful! Thanks so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants