-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Inline comments always stripped from .d.ts, including @ts-expect-error, @ts-ignore etc. #59365
Comments
I really think this needs to be revisited.
@RyanCavanaugh mentioned:
But silencing the error at the use site is all I want to do. I'm well aware it doesn't affect downstream types- that's exactly the point. The downstream types are already correct, I just don't want users having their builds broken because I or some other author used @andrewbranch Are you aware of workarounds for cases like those I mentioned or open to reconsidering this behavior? |
We are already unhappy with people using Why do you need to do this? Why is error-free code not viable here? |
I understand by doing this I'm opting into "unsafe" behavior that could break in a future version of TS, but all of my types are tested and the only thing should matter for an external consumer is that the output is correct, not whether my implementation in some environment is determined to include an error. As mentioned, there are a few cases where as far as I'm aware, the only way to get the type-level behavior desired is with internal code that requires some ignore comment. For example, TS occasionally can't identify that it is safe to treat a class as covariant due to some conditionals that it fails to precisely evaluate, but I can overwrite the annotation so downstream users get the correct behavior by manually annotating it with To be honest though, I think it is probably true that 95%+ of the time that That said, I don't believe that stripping them from The behavior intended by the person publishing the types is clearly whatever behavior they're already seeing locally, with the comment added. No matter how bad you think these comments are, emitting |
This just isn't a supported use of |
I know that I can work around this using block-style comments, so no post-process is required (as long as I'm willing to put up with some mildly wonky JSDoc suffixes on hover). My main concern is that regardless of how necessary for most people to employ these comments, the reality is that they're very common, and having them stripped out unless they're written as block comments does not feel intuitive or beneficial to anyone involved. If it's just not a priority I can understand that, but I just don't see any upside to potentially exposing downstream errors that were intentionally suppressed in library code. |
That they're not removed when writing |
@MartinJohns I agree that this is an inconsistency, so the question then becomes how to resolve it. I still can't wrap my head around who it benefits to strip these out. |
This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
π Search Terms
ts-expect-error ts-ignore removeComments .d.ts emit stripped
π Version & Regression Information
This is the behavior in every version I tried
β― Playground Link
https://tsplay.dev/wjje8w
π» Code
π Actual behavior
.d.ts
outputπ Expected behavior
.d.ts
outputAdditional information about the issue
I expect the issue is probably determining whether certain comments "belong" to JS implementation or
.d.ts
, and it assumed that only block-style comments that appear as JSDoc should be long to the types.I think there are likely other cases where comments on types should be preserved (e.g. a comment within a generic type implementation that is not emitted to JS), but at the very least, comments that affect type checking like
@ts-expect-error
and@ts-ignore
should always be emitted.The text was updated successfully, but these errors were encountered: