【问题标题】:Using generators in Typescript tsconfig在 Typescript tsconfig 中使用生成器
【发布时间】: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 onethis 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


【解决方案1】:

知道了,我使用的是 Visual Studio 2019 预览版,由于某种原因,2017 年运行良好。原来我只需要安装3.2.2 SDK 并且在两个版本中一切正常。我不知道为什么 2017 年不关心 SDK 没有安装,而 2019 年却安装了,看起来很奇怪。

【讨论】:

    猜你喜欢
    • 2019-12-06
    • 2016-06-08
    • 1970-01-01
    • 2019-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-02
    相关资源
    最近更新 更多