TypeScript找不到名称forEach

时间:2017-04-13 10:35:38

标签: typescript

我正在尝试在我的TypeScipt程序中使用forEach,如下所示:

const treeForEachDF: <T>(f: Command<T>, tree: Tree<T>)=>void =
(f, tree) => {
    f(tree.root);
    if (!treeLeaf(tree))
        forEach(x => treeForEachDF(f, x), treeChildren(tree));
};

但是,我收到以下错误:

“TS2304找不到名称'forEach'”

我的tsconfig.json:

{
   "compilerOptions": {
   "module": "commonjs",
   "target": "es5",
   "noImplicitAny": false,
   "sourceMap": false,
     "types": [
        "node"
     ],
     "typeRoots": [
        "node_modules/@types"
     ]
},
    "exclude": [
    "lib/startup.ts",
    "node_modules/",
    "typings/"
    ]
}

1 个答案:

答案 0 :(得分:0)

显然有一种方法可以使用forEach,因为我首先尝试从'ramda'导入它,如下所示:

import {map, reduce, forEach} from 'ramda'