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

Error 2488 only shown once #46272

Open
danny12321 opened this issue Oct 8, 2021 · 6 comments
Open

Error 2488 only shown once #46272

danny12321 opened this issue Oct 8, 2021 · 6 comments
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@danny12321
Copy link

Bug Report

When the error Type '{type}[] | undefined' must have a '[Symbol.iterator]()' method that returns an iterator.(2488) occurs multiple times in a project it only shows once.

image
As could be seen in the image above only data_1 has red underline, while I expect to also have red underline by data_2.

🕗 Version & Regression Information

When using es5 or older both errors are shown, but from es6 only one error shows.

⏯ Playground Link

Playground link with example

💻 Code

// using math.random to create type string[] or undefined
const data: string[] | undefined = Math.random() ? [] : undefined;

const data_1 = [...data]; // has a error shown
const data_2 = [...data]; // has no error shown

🙁 Actual behavior

The TypeScript compiler is only returning one of the multiple errors when the error is of type 2488.

🙂 Expected behavior

The TypeScript compiler should return all the locations of the errors, even if they are the same type. This would be handy for code analysis tools.

@andrewbranch
Copy link
Member

The TypeScript compiler should return all the locations of the errors, even if they are the same type.

This is not something we’re interested in doing in general, but this particular example looks surprising to me and feels like probably a mistake.

@andrewbranch andrewbranch added the Needs Investigation This issue needs a team member to investigate its status. label Oct 8, 2021
@andrewbranch andrewbranch added this to the Backlog milestone Oct 8, 2021
@danny12321
Copy link
Author

Even when ignoring the first error the second will still not show. This makes compiling with compile errors (that are not showing) possible.
image

But when creating a copy both errors show which is interesting.
image

@simondel
Copy link

I would expect all errors to be shown when the compilation fails so I can fix all errors at once.

@nicojs
Copy link

nicojs commented Dec 9, 2022

This is a more significant issue than it first appears. If you ignore the first error with // @ts-expect-error, one would expect the compiler to error on the next one, but it doesn't:

https://www.typescriptlang.org/play?#code/PTAEFcGcEsDsHNQFsCGAXAFgOgE4tgCYD2SoaRoAxjgKbo1kCeADg5GjnPANoC6oRHBEI0AZnBoEAUJSKx2oAuhQAuUO04I+oAD7CCYiQVABeUAFl02PIRIAKAJSgA-KG1rwI8bEkBuKVIgoAACaJAAtDQAHqyUaJE4OIIycgpKaCgA+gCMpm5YBekovL6gQRgokKAooDSJguoYRADusAGy8miKypkATHncBVhFJWVgFVWwFHVJQpBNrVJAA

This feels like a clear bug to me.

image

@RyanCavanaugh
Copy link
Member

Everything bad we predicted from implementing ts-ignore continues to manifest 😕. Biggest regret I have honestly.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this and removed Needs Investigation This issue needs a team member to investigate its status. labels Dec 9, 2022
@nicojs
Copy link

nicojs commented Dec 10, 2022

Thanks for the response @RyanCavanaugh 🙏.

Also without the @ts-expect-error family of problems here, tools/users might rely on full error reporting. I believe that is also a design goal.

We at StrykerJS rely on a full error report in order to validate multiple mutants at the same time in stryker-mutator/stryker-js#3900.

nicojs pushed a commit to stryker-mutator/stryker-js that referenced this issue Feb 10, 2023
Add grouping mutants to the `@stryker-mutator/typescript-checker` to improve performance.

The typescript checker is slow because mutants are checked for compile errors one by one. Each time a mutant is checked, TypeScript will do full type-checking. This is sped up by running multiple checkers in parallel, using typescript's `--watch` mode, and only compiling in memory. Yet still, this is very slow, as a rule of thumb: 10x slower than not enabling this checker.

This PR improves this by grouping mutants unrelated to each other in the same typescript compilation run. Any compilation errors that result from one of the mutants in a group can always be associated with one mutant. 

One downside to this approach is that a TypeScript compilation sometimes forgets to report some of the errors (although it is a design goal of TypeScript to report them all). For example microsoft/TypeScript#46272

This is why you disable this grouping behavior by adding:

```json
{
  "typeScriptChecker": {
    "prioritizePerformanceOverAccuracy": false
  }
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

5 participants