【问题标题】:How do I reference a Screeps typescript file?如何引用 Screeps 打字稿文件?
【发布时间】:2020-01-29 17:53:23
【问题描述】:

我有一个 tsconfig.json:

{
    "compilerOptions": {
        //"noImplicitAny": "true",
        //"removeComments": "true",
        "target": "es5",
        //"sourceMaps": true,
        "outDir": "../compiledjs"
    },
    "files": ["./node_modules/screeps-typescript-declarations/dist/screeps.d.ts"],

}

我正在尝试像这样使用 Screeps 特定的 Javascript 函数:

Source.prototype.harvesters = function () {
    var creeps = this.pos.findInRange(FIND_MY_CREEPS, 1);
    return _(creeps).filter({ memory: { role: 'harvester' } }).value();
}

但我不断收到错误消息,因为 VS 代码无法识别 Source。我在这里做错了什么?

【问题讨论】:

  • 您不需要更改tsconfig.json,打字稿应该会自动选择它。但是您确实需要导入Source类型。
  • 源定义在类型文件中。即使我将它作为导入包含在我的文件顶部,它也无法解析
  • 您能否展示包含导入的代码示例?这是执行此操作的正确方法。您尝试此操作的方式可能有误。
  • 其实我收回了。看看那个包,他们似乎不使用模块,而是使用全局变量。我对声明新全局变量的工作方式不够熟悉,所以我可能弄错了。

标签: typescript screeps


【解决方案1】:

tsconfig.json 文件具有属性typeRoottypes 到特定类型信息。 您的 tsconfig 在 files 而不是 types 中包含类型信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-23
    • 2018-01-06
    • 2017-12-28
    • 2017-05-13
    • 2019-05-02
    • 2017-06-28
    • 1970-01-01
    相关资源
    最近更新 更多