Microsoft/TypeScript

Strange error: string is not a string type

开放

#41,918 创建于 2020年12月10日

 (6 条评论) (0 个反应) (0 位负责人)TypeScript (13,395 个派生)batch import
BugDomain: Error MessagesEffort: ModerateHelp Wanted

仓库指标

星标
 (108,860 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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.

贡献者指南