tsdjs / tsd

Check TypeScript type definitions
MIT License
2.4k stars 67 forks source link

Add `expectDocCommentIncludes` assertion #155

Closed tommy-mitchell closed 2 years ago

tommy-mitchell commented 2 years ago

Adds an assertion to check the documentation comment of a given expression:

/** FooBar */
const foo = 'bar';

expectDocComment<'FooBar'>(foo);

Fails if the type parameter does not exist, is not a string literal, or does not match the given expression's doc comment.

In one project, I have a function that takes a set of user-defined extension functions and maps them onto the built-ins. expectDocComment can help ensure that the type hinting for the user-defined extensions are mapped correctly.

sindresorhus commented 2 years ago

It doesn't really make sense to me that it's matching the whole doc comment. That would make the assertion huge. I think something like expectDocumentationCommentToContain() would be more practical. So you can assert that the doc comment contains a certain substring.

tommy-mitchell commented 2 years ago

I agree, I wanted to see what your thoughts were before making the match non-exact. I went with expectDocCommentIncludes since it's less verbose and matches string.includes().

sindresorhus commented 2 years ago

Can you fix the merge conflict?

tommy-mitchell commented 2 years ago

Merged.