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

[dtslint] Possible to opt out of ts-ignore flagging? #511

Closed
thw0rted opened this issue Aug 8, 2022 · 2 comments
Closed

[dtslint] Possible to opt out of ts-ignore flagging? #511

thw0rted opened this issue Aug 8, 2022 · 2 comments

Comments

@thw0rted
Copy link

thw0rted commented Aug 8, 2022

I know everybody thinks they have a good reason why they really need ts-ignore, but, please hear me out.

I would like to help fix some types for an isomorphic library. I've been looking for a non-terrible way to do this for quite some time. There are several proposals out there to address the problem (e.g. microsoft/TypeScript#31894 and microsoft/TypeScript#3538) but unfortunately none have actually been implemented.

In the interim, I'm pretty sure I have found an ugly, dirty hack of a workaround that I'm pretty sure completely solves the problem with no side effects. Unfortunately, it requires tactical use of @ts-ignore:

// @ts-ignore
type NodeReadableStream = any extends NodeJS.ReadableStream ? never: NodeJS.ReadableStream;

If the consuming project includes @types/node, the above will be an alias to ReadableStream. If they do not, it will be never (and thus cleanly erase out of type unions). Without @ts-ignore, though, it will break the build and require consumers to use skipLibChecks.

I started to use the above workaround in a type package update but the tests failed with 'ts-ignore' is forbidden. I only found one previous issue discussing this error, but it was about an ignore-comment in a dependency. Is there a way to intentionally introduce a ts-ignore into a types package? If not, can we get one? (If not, does anybody have a better workaround for the problem than mine?)

@thw0rted
Copy link
Author

A commenter in another thread posted code with // eslint-disable-next-line @typescript-eslint/ban-ts-comment, but I assume dts-lint does not respect that out of the box. It could provide an example syntax for implementation, at least.

@jakebailey
Copy link
Member

This is now possible as of #700, though you definitely should not use this if a better option is available, which should be true basically always.

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

No branches or pull requests

2 participants