GithubHelp home page GithubHelp logo

Comments (9)

jakebailey avatar jakebailey commented on August 29, 2024 1

We are already unhappy with people using ts-ignore and then trying to use whatever resulted from that operation. I think explicitly letting that happen in d.ts files is even worse...

Why do you need to do this? Why is error-free code not viable here?

from typescript.

MartinJohns avatar MartinJohns commented on August 29, 2024

@ts-expect-error and @ts-ignore should always be emitted.

These are intentionally not emitted. See #43570 / #38628.

from typescript.

ssalbdivad avatar ssalbdivad commented on August 29, 2024

I really think this needs to be revisited.

  1. You can still enforce those comments in .d.ts with block style like /** @ts-expect-error **/, but it looks awful in JSDoc
  2. There are cases like the one I mentioned and "casting" variance annotations where there is no other method of working around the error
  3. skipLibCheck is still off by default, meaning this can very easily break downstream builds

@RyanCavanaugh mentioned:

@ts-ignore silences errors at the use site and does nothing else; this is exactly its intended behavior.

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 // instead of /** **/.

@andrewbranch Are you aware of workarounds for cases like those I mentioned or open to reconsidering this behavior?

from typescript.

ssalbdivad avatar ssalbdivad commented on August 29, 2024

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 out and then ignoring it. In terms of safety, it is fundamentally no different than any other cast; I'm just prompting TS that I know something is safe to treat a certain way and to trust my judgment.

To be honest though, I think it is probably true that 95%+ of the time that // @ts-ignore or // @ts-expect-error are used outside a test, it's a mistake. Casting or performing additional checks or intersections would be the better approach. So I understand why you want people to avoid these comments.

That said, I don't believe that stripping them from .d.ts output is actually helping anyone realize when they're being used incorrectly. It's just creating potential downstream problems for consumers of those types that have nothing to do with the output of the types themselves.

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 .d.ts that is semantically different (i.e. can lead to different build results) does not feel like a solution.

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on August 29, 2024

This just isn't a supported use of ts-ignore and we're not going to open the enormous can of worms it would be to correctly detect when these comments should/shouldn't be in the output. It's even more fraught for something like ts-expect-error where an error might be conditional on compiler settings. If you are truly breaking the type system in a way that you fully understand, putting up the high bar that you need to post-process your output seems entirely appropriate.

from typescript.

ssalbdivad avatar ssalbdivad commented on August 29, 2024

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.

from typescript.

MartinJohns avatar MartinJohns commented on August 29, 2024

having them stripped out unless they're written as block comments does not feel intuitive or beneficial to anyone involved.

That they're not removed when writing /** @ts-expect-error **/ seems like a bug to me.

from typescript.

ssalbdivad avatar ssalbdivad commented on August 29, 2024

@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.

from typescript.

typescript-bot avatar typescript-bot commented on August 29, 2024

This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

from typescript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.