[dtslint] Possible to opt out of ts-ignore flagging?
thw0rted opened this issue · 2 comments
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?)
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.