Skip to content
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

types 3.0: add type tests #1906

Open
filmaj opened this issue Aug 29, 2024 · 4 comments
Open

types 3.0: add type tests #1906

filmaj opened this issue Aug 29, 2024 · 4 comments
Labels
area:typescript issues that specifically impact using the package from typescript projects enhancement M-T: A feature request for new functionality pkg:types applies to `@slack/types` tests M-T: Testing work only

Comments

@filmaj
Copy link
Contributor

filmaj commented Aug 29, 2024

Using a package like tsd, we can write basic tests for the type interfaces. For more complex types this can be extremely useful, especially during refactoring, to ensure the end-user experience stays consistent / we don't regress on the developer experience that TS provides.

@filmaj filmaj added enhancement M-T: A feature request for new functionality tests M-T: Testing work only area:typescript issues that specifically impact using the package from typescript projects pkg:types applies to `@slack/types` labels Aug 29, 2024
@filmaj filmaj added this to the [email protected] milestone Aug 29, 2024
@mrazauskas
Copy link

Consider employing TSTyche for this job, https://github.com/tstyche/tstyche

It can test using different versions of TypeScript (tstyche --target 4.8,5.2); is lightweight (~225kB); has --watch mode; and much more (for instance, documentation website: https://tstyche.org/guide/introduction).

@filmaj
Copy link
Contributor Author

filmaj commented Oct 24, 2024

Thanks for the suggestion @mrazauskas. We have been using tsd in other projects of ours, like bolt-js (you can see its type tests here).

@mrazauskas
Copy link

mrazauskas commented Oct 25, 2024

Sure. It is up to you. I was chiming in, because you wrote “a package like tsd”.

Simply find five minutes and give TSTyche a spin. I am sure you will like it (;


Indeed, tsd is very popular library. But let me show you something:

import { expectAssignable, expectNotAssignable, expectNotType, expectType } from "tsd";

type T = { a: 1 };

expectType<T>({ a: 1 }); // pass!
expectNotType<T>({ a: 1 }); // pass! hm.. what?!

expectAssignable<T>({ a: 1 }); // pass!
expectNotAssignable<T>({ a: 1 }); // pass! wait a moment..

That’s a bug which known for more than two years (tsdjs/tsd#141). And it is easy to fix. The problem is that positive assertions and their negated counterparts are evaluated using different logic instead of !result. I was maintaining a forked tsd-lite, it did not have this issue. Also many limitation were fixed (for instance, here is one you know already: slackapi/bolt-js#1053 (comment))

That was fun project, but I wanted to have goodies like test.skip(), test.only() or expect.fail(). Of course, one can use comments like // fix me: or so. That works, but I wanted a better type testing tool. That’s how TSTyche was born.

As I mentioned, its install size is only ~225kB. Zero dependencies. Works like a clock, packed with goodies, tests on specific version of TypeScript, has --watch mode, etc. That is way more than tsd can do, but tsds install size is 48.0MB. Obviously it comes with TypeScript baked in, but you already have it installed. Or? And also install size of the latest typescript is only 21.4MB. Oh well..

Don’t get me wrong. I think tsd is a useful project. But, as it happens with open source, have to admit that it got abandoned (here is an illustration: tsdjs/tsd#196).

@filmaj
Copy link
Contributor Author

filmaj commented Oct 25, 2024

Great points; I will certainly take a look at TSTyche, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:typescript issues that specifically impact using the package from typescript projects enhancement M-T: A feature request for new functionality pkg:types applies to `@slack/types` tests M-T: Testing work only
Projects
None yet
Development

No branches or pull requests

2 participants