【发布时间】:2019-05-15 04:33:04
【问题描述】:
我要做什么
这很简单,我想在 Typescript 中使用生成器函数,并且不会出错。
traverseTree = function* (tree: Section[]) {
for (let branch of tree) {
yield branch;
if (branch.Children.length > 0)
yield* traverseTree(branch.Children);
}
}
我看到了什么
编译时出现错误TS2318 Cannot find global type 'IterableIterator'
到目前为止我做了什么
我已经阅读了许多问题,例如 this one 或 this one,但我找到的所有建议都没有起到任何作用。我正在使用 Typescript 3.2.2 并尝试使用一个非常简单的生成器函数。我尝试了很多东西,但这是我当前的 tsconfig 文件:
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es5",
"module": "none",
"lib": [
"esnext",
"dom",
"es2015.promise"
]
},
"compileOnSave": true
}
我还尝试在"lib" 中添加"downlevelIteration": true,"noLib" 的真假@:没有"esnext",使用"es6",根本没有"lib",我也搞砸了带有设置文件:
"files": [
"node_modules/typescript/lib/lib.d.ts",
"node_modules/typescript/lib/lib.es6.d.ts"
]
我所做的似乎没有任何区别,我在编译时总是得到完全相同的错误。
【问题讨论】:
-
你如何编译你的项目?
-
compileOnSave标志在那里,我只是 ctrl+s 我的项目和 VS 编译一切
标签: typescript generator