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/"
]
}
显示当前的tsconfig。 –
你可以显示调用'forEach'的代码片段吗? –
我假设你想在'treeChildren(tree)'中的每个对象上运行'treeForEachDF'。你有没有尝试:'treeChildren(tree).forEach(child => treeForEachDF(f,child));'? –