Microsoft/TypeScript

Strange error: string is not a string type

Open

#41,918 opened on 2020年12月10日

GitHub で見る
 (6 comments) (0 reactions) (0 assignees)TypeScript (6,726 forks)batch import
BugDomain: Error MessagesEffort: ModerateHelp Wanted

Repository metrics

Stars
 (48,455 stars)
PR merge metrics
 (平均マージ 6d 17h) (30d で 9 merged PRs)

説明

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.

コントリビューターガイド