首页 > 解决方案 > 如何引用 Screeps 打字稿文件?

问题描述

我有一个 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. 我在这里做错了什么?

标签: typescriptscreeps

解决方案


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


推荐阅读