Microsoft/TypeScript

Strange error: string is not a string type

オープン

#41,918 opened on 2020/12/10

 (6 件のコメント) (0 件のリアクション) (0 人の担当者)TypeScript (13,395 件のフォーク)batch import
BugDomain: Error MessagesEffort: ModerateHelp Wanted

Repository metrics

Stars
 (108,860 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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.

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