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
Support @ts-ignore for specific errors #19139
Comments
Seconding (and wanting to track this) This would be super helpful in our case as we have a class with a bunch of variables, and a function that accesses them by key value (vs direct getter function). As a result, they are never called directly within the class and are throwing the error despite being necessary to the functionality. I don't want to have to disable the "noUnusedLocals" check across the board, just in the two classes where this is the case. Edit - |
I would also love this, more specifically for the noUnusedLocals rule, we get errors on this:
Saying that BinaryExpression is not used, but it might be, depeding on the value of this.expression.type. I could make BinaryExpresison public, but I really think it is a private method. |
This would also be very useful for our team, we are slowly migrating a large JS app to TS. We'd like to turn on strict compilation flags (especially Specific error suppression would allow us to gradually migrate everything to strict compilation. |
It's actually absurd that this is even still an issue. I've experienced a problem related to this. The underlying cause was due to a typescript change in 2.4, as discussed here: We were then left with three options
option 1 is not preferable, as it means we can't leverage any new typescript features and can result in having mismatched dependencies options 2 and 3 are possible (although difficult), and they really only handle one such specific 'error' preventing successful compilation. Why is there not an option for us to 'ignore' TS2559 (as an example)? |
@Ristaaf I know it's been a while, but I think your use case ( |
Here's another little doozy that I don't believe is covered by any "normal" TS methods. Consider the following: You're dynamically creating a web worker, i.e. by using an const objectUrl = URL.createObjectURL(
new Blob(
[`(${
function() { ... }.toString()
})()`],
{ type: 'application/javascript' }
)
); ...and the body of that function contains the single most important thing a web worker can do, // inside worker function
setInterval(() => postMessage('from worker!'), 2000);
// ^^^ this causes TS error! 😿 Oh no! TypeScript's implementation of // inside worker function
setInterval(() => postMessage('from worker!', null), 2000);
// ^^^ this causes worker exception! ☠️ The web worker postMessage won't accept another parameter! Woe is me. Since it doesn't make sense to change the [correct] type definition for the window context's interface, and web workers can't use TypeScript [natively], it seems this would be a perfect opportunity to tell the TS compiler "Hey dude, that's a stringified version of some arbitrary Javascript that has nothing to do with you, your execution context even. Back off, get your own sandwich". |
@wosevision disclaimer: I never worked with Webworker till now. |
@HolgerJeromin Thanks, I appreciate the tip. I was aware of the TS webworker lib and target, but this situation is slightly different. The linchpin point is here:
...That is to say, the target is not a webworker. It's just regular browser JS that happens to be building the webworker. The lib should still reflect the regular lib.dom.d.ts because, for all intents and purposes, we are not inside a webworker and therefore lib.webworker.d.ts typings are useless everywhere else. It's such an edge case that it would feel silly to do anything other than ignore a line or two. |
Is there a reason this issue is still open? I depend on a library that has an incorrect documentation, and it causes unsilencable errors! See esteban-uo/picasa#27 for more info. This feels a bit silly. |
@jlengrand you could use a generic |
Ha nice, I didn't understand that! I saw the ts-ignore issue closed, thinking it had been dismissed. Thanks for the tip! |
Without fine control about how legacy files are handled it is really hard to introduce new typescript rules into a project. Please give this use case some more consideration. |
|
@RyanCavanaugh In my specific case I'm running into a problem related to immer losing symbol keys which I believe is caused by keyof removing well known symbols. For this case I have to use a ts-ignore statement. I think adding some compiler options would really help because ideally I want to remove these I think for I think the same approach where specific error Even if you don't opt into either of these behaviors you have the ability to periodically run a build with these rather than checking each line manually. |
Personally, I find entire TSC errors to be, without explicit rationale behind them, 100% useless. Oops, I broke at least 3 TS rules at once :) There are plenty of errors that are just that, errors, they should make someone stop and think about whether what they had just written was unsafe, and rewrite it, but the "errors" that I would like to disable en masse fall into a whole different category outside of safety and linting, into the area of "why is that an error in the first place?" |
For both TS18022 and TS18019, your linked issue points out that private methods only reached "Stage 3" quite recently and TS hasn't gotten around to supporting them yet. Likewise for other up-and-coming ES private features ( For TS2775, the linked issue (and a PR that is linked several times from there) make it pretty clear that there's a design limitation for control-flow analysis where you have to basically "re-type" the assert function when it's imported. (I agree with what appears to be the general consensus that the error message could be clearer, but at least searching for that error number brings you to those discussions.) This is irksome but not insurmountable. |
I think I'm experiencing a different error now that I look at it; I already know that reassigning an assertion function requires an explicit type, but what about direct calls? let azzert = new Assertion().assert;
azzert(foo); vs new Assertion().assert(foo); my particular case looked more like: class T {
static #assertIsT(x: unknown): asserts x is T { ... } // error
method(x: unknown) {
T.#assertIsT(x); // error
...
}
} but the real problem here is the lack of static private support and is the only reason that it can't be typed correctly.
Well... those issues have actually been open for quite some time, 10 and 11 months respectively. But, in reality, the numbers are a bit different:
An average of three years since they reached stage 3; these are bound to reach stage 4 soon. Also, there are errors like TS2376 and TS17009, which seem... like they fulfill the same role, why does one exist, if the other does? class T extends H {
foo = ...;
constructor() {
const x = bar();
super(x, x); // TS#### : "don't do that"
// do I do this? // super( bar(), bar() );
}
} |
I am not a Typescript expert, so I'll not add arguments of the previous debate. However, I would like to express the need of this granularity with an example. I use export type MyStackParamList = {
Index: undefined;
Show: {
id?: string;
};
Edit: {
id: string;
};
};
const Stack = createStackNavigator<RidesStackParamList>(); You may define multiple stacks like that, but I will not going to details here. Using the navigation.navigate('Payment'); Typescript will throw error However, this code part works like a charm. You can navigate to an another route of an another stack without issue Is it me wrongly using the library? Maybe, surely. It's classified. However, supposing it's an issue related to the vendor type definition, I can do anything waiting the fix than ignoring the error. But as @andy-ms said, I would like to be sure only this error will be silenced and avoid possible other mistakes on the same line. If specifying errors to ignore is dangerous according to some people here, what are the alternative for this case? Thanks for reading |
The only actual argument, if I'm not mistaken, is the instability of the error codes. A couple thoughts
All we are asking for is the ability to ignore those errors that we deem to be more style than error especially when the code actually runs, yet not have to not turn everything off. The general reply in effect is that it is a bad idea to turn off errors but if you have to then turn them all off which makes no sense at all whether at the global or individual line level. What would the actual level of effort be to implement ignorable/expectable error codes at the comment AND tsconfig level for consistency? If it were implemented, would the folks in this thread be ok with the ts compiler generating a report of ignored errors that could in some way (via opt-in program) reported back to the ts dev team so that they can have some real world feedback on what all is getting ignored? My problem with suggestions like "we are not seeing issues with ..." is that you aren't looking at any real code. You are waiting for the rarified people who know enough to complain, and with enough time to, to actually complain. To make those kind of arguments you need real feedback but if you are making it so we can't know what the errors we're ignoring are, except all of them, then how can you possibly know that your errors are useful or what the consequences of your choices are? I'm thinking there is an opportunity for a meaningful feedback loop and a win-win if you let us codify our overrides inline with some metric info going back to you rather than have to come here to complain about things, // @ts-ignore TS/1234 because I know what I'm doing |
@arthur-clifford could not agree more |
The other big argument is error code specific ignores on a single line. Suppose you want to ignore two specific errors on the same line, you should be able to Having a more granular "hold the line" functionality would be a massive boon. |
I'm really looking to this feature and it really important IMO (I'm sorry if it's already been said...)
The problem with using error code numbers (e.g. |
Another case where disabling specific error is useful is refactoring large codebase. |
i know im in a tiny minority here, but i (try to) have some sanity types to enforce relations (?) between various variables/types etc. since they have zero use, they always trigger ts(6196) aka type declared but never used. |
Adding my voice to the choir here. I inherited an old, large TS codebase where at some point someone decided to suppress the errors in the webpack build. With > 4,000 TS errors that spring up after fixing it, a single "Big Bang" PR to fix them all is unrealistic. I assumed I could just write a script to funnel the newly-identified errors identified from the linter into a script to add file-level @ts-ignore's, thus suppressing the specific errors in each file, then we could tackle the monstrous job of fixing all the problems piecemeal afterwards. But without the option to ts-ignore specific errors I find myself scratching my head... |
@benkeen to be clear, neither If By the way, not to make light of your situation, but disabling all the strict checking might reduce your issue to one that is easier to manage. |
I really like that Flow forces me to ignore specific errors: < // $FlowFixMe[incompatible-variance]
< // $FlowFixMe[incompatible-type]
< // $FlowFixMe[prop-missing]
> // @ts-ignore: Uhh.
foo(bar) Slightly unrelated, but would be better if errors could match offending lines more closely: > // @ts-ignore: Can't assign number.
process.env = {
FOO: 'bar',
< // $FlowFixMe[incompatible-type]
QUUX: 1000,
} |
For this feature, if it wasn't thought/said before, I would be expecting something like I also don't like the |
Another use case where I actually want warnings, but not all of them: export function notEmpty<TValue>(
value: TValue | null | undefined
): value is TValue {
if (value == null) return false;
const testDummy: TValue = value; // for compile warning
return true;
} I want a compile warning for the type check, but I don't want a warning for it being unused. Yes, I can add a line like |
Jonas, what you want is a "type expectation". There are a number of libraries that provide an https://github.com/microsoft/dtslint etc |
I'm repeatedly coming back to this issue. Having said this, all the places where I see a reaction from a TS representative, I see wrong arguing. Focusing on
I see 3 problems with this (at least):
|
Following |
TypeScript Version: 2.6.0-dev.20171011
Code
Expected behavior:
Ability to make
ts-ignore
apply to the--noFallthroughCasesInSwitch
error but not to other errors.Actual behavior:
case "1":
would also compile.The text was updated successfully, but these errors were encountered: