2017-04-13 75 views
0

我想使用的forEach我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/" 
    ] 
} 
+0

显示当前的tsconfig。 –

+0

你可以显示调用'forEach'的代码片段吗? –

+0

我假设你想在'treeChildren(tree)'中的每个对象上运行'treeForEachDF'。你有没有尝试:'treeChildren(tree).forEach(child => treeForEachDF(f,child));'? –

回答

0

显然存在使用的forEach正如我在尝试的方式首先,从'ramda'进口它时如下:

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