-
-
Notifications
You must be signed in to change notification settings - Fork 542
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
Drop tsd for tests in favor of expect-type #499
Conversation
For context, this update was written using pattern matching. For our use case, |
Considering the fact that @sindresorhus is a (co-)maintainer of |
97661a8
to
727b7e9
Compare
`tsd` is a somewhat heavy-weight dependency that is unnecessary considering that `expect-type` is already a depdency of `type-fest`.
727b7e9
to
1bd0fa2
Compare
expect-type does not give any information about the type of error but only tells you that there is a problem here. I don't find it very useful compared to tsd. // @voxpelli |
@voxpelli definitely not enthusiast. The error messages don't describe anything and are more confusing than anything else (or I missed something), see the screen in my previous comment. |
@skarab42 Absolutely, was thinking you could highlight that as an actual review comment, that's why I added you in, sorry for confusion 🙈 |
Sorry I don't know how to do this when it's not attached to code. I don't like how the error messages are produced, but I love the Jest like API. So a few months ago, I have made a plugin for vitest that supports both APIs (tsd & jest like). https://github.com/skarab42/vite-plugin-vitest-typescript-assert We can either use my plugin, but we must to switch to vitest. Or I can make a PR on tsd to support the API a la Jest. |
Hey all! Yeah, I realized this would be a controversial change. I did see that As for bad error messages in I'll link that from here once it's ready to go. |
Here's the PR for |
It's still not an error message, what happens when tsc report the error? At the moment I don't see any advantage in changing the test library, especially if it doesn't bring any benefits. |
Indeed it was introduced by its author when he added the |
Hi all! expect-type author here. I'm a fan of tsd and borrowed from it plenty when writing expect-type - I didn't have any evil plan to sneak it in. expect-type trades off (some) DX for lightweightness, simplicity and most importantly, type-safety. IMO there are also some other DX advantages to compensate like the fluent API, but that's a matter of taste. The reason expect-type was used above was because of a bug that is pretty dangerous, IMO, in tsd, making it not trustworthy for testing generic functions: tsdjs/tsd#142 (I am also the author of that issue). I'll dig out the discussion with @sindresorhus around it, can't remember if the main back and forth was on dot-prop or type-fest right now. He did indeed request at first that we use tsd, but the above tsd issue was making tests pass in CI despite there being a bug in the library (which expect-type found - so I do support this change). Points taken about the CLI error messages though - no doubt tsd is better in that area. My team use CI to catch when there's an issue, then vscode + hover + squinting to see what it is. But yes, it can get difficult to do that when it's complex. I'm excited to see if the above PR can improve them though. Also for those interested, here's a PR relying on the proposed "throw types" typescript feature which would be even better: mmkal/ts#152 |
Here's the discussion I was thinking of in dot-prop: sindresorhus/dot-prop#92 (comment) And here's the suggestion by @sindresorhus to use expect-type instead of tsd in type-fest: #153 (comment) (which I had forgotten was earlier than the dot-prop PR, but the point still stands - it's really, really important that type-fest has correct types, more important than its maintainers having nice error messages in CI, IMO) As far as I know, the bug is unfixable with tsd's current design. |
@mmkal First of all, thank you for taking the time to answer so precisely. I must admit that I did not look very far in the commit messages.
I suspected not, which is why I asked for clarification.
This is a very good reason, I was not aware of this bug (which must also be present in my lib).
I've been dreaming about this for a long time 💜
That's true, but it's even better to have both ;)
I'll look into it as soon as I can. |
Libraries with heavy dependencies make them less attractive. Anecdotally, for us, keeping Also, having the exact same "tester" for the implementation + tests ( |
@mmkal Juste made a PR to add a Jest like API to tsd tsdjs/tsd#168 which by the way makes the bug with generics disappear by design. |
@trevorade I agree, This is why I created a hybrid solution https://github.com/skarab42/unleashed-typescript for my plugin, still not ideal but it avoids maintaining a custom version of TS and it allows to have a version of TS synchronized with your environment. |
@skarab42 That's pretty cool. My only concern with adopting such an approach is that it appears to run the risk of an unstable API where the |
Another naming option could be |
Gonna go ahead and close this for now. I can recreate it in the future if there is a consensus that |
@trevorade I personally would be in favor of picking up this discussion again, to get the canary tests working, especially as they are now part of the TS canary tests (I reopened this thinking it was an issue, not a PR, feel free to open a new issue / PR and ping me as the one who requested it) |
2024 update: expect-type now has much improved error messages, so in most cases, it will be clear what's wrong when something breaks in CI, if there's interest in giving this another go. |
@mmkal Improvements are always welcome! I have a bit of a hard time remembering where we left of here and what the status of it all is right now, but feel free to open an issue or make a proof of concept PR and we can take the discussion from there (you can refer to this comment if you want) Since this is an old closed comment any discussion here is doomed to be lost in the sea of notification fatigue (at least for me) |
tsd
is a somewhat heavy-weight dependency that is unnecessary considering thatexpect-type
is already a dependency oftype-fest
.