Microsoft/TypeScript

Strange error: string is not a string type

Open

#41.918 geöffnet am 10. Dez. 2020

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

Repository-Metriken

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

Beschreibung

TypeScript Version: 4.1.2

Search Terms: downlevelIteration, string, spread

Code

function test(name: string) {
    for (const _char of [...name]) {
    }
}

Run tsc on just this ts file with no extra flags (I couldn't find the right combination of playground checkboxes to simulate this.

Expected behavior: Assuming the code is wrong, the error message should probably not say that string is not a string type.

Actual behavior:

error TS2569: Type 'string' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of 
iterators.

Contributor Guide