Microsoft/TypeScript

Error 2488 only shown once

Open

#46.272 geöffnet am 8. Okt. 2021

Auf GitHub ansehen
 (6 Kommentare) (5 Reaktionen) (0 zugewiesene Personen)TypeScript (6.726 Forks)batch import
BugDomain: Related Error SpansHelp Wanted

Repository-Metriken

Stars
 (48.455 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 6T 17h) (9 gemergte PRs in 30 T)

Beschreibung

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.

Contributor Guide