2017-04-13 112 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'