打字稿错误: - 类型'string'上不存在属性'forEach'

时间:2017-03-06 05:56:08

标签: angular typescript

每当我使用forEach()时,我在终端

中收到此错误
[ts] Property 'forEach' does not exist on type 'string'.

我的应用程序在浏览器中正常运行。一切正常,但我不想在终端中出现这样的错误。

我使用下面的代码。请告诉我我错过了什么。

 job.forEach(function(state) {
        if((totalcarer['userId']+"")===state.rNo)
        {
          cjobState = state.cJobstatus;
        }
      });

1 个答案:

答案 0 :(得分:4)

arrays: string[];
arrayString: string;

看到两者之间的差异?一个是数组,另一个是字符串。

arrays.forEach(...) // valid.
arrayString.forEach(...) //invalid.
相关问题