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));'? –