找不到打字稿函数

Typescript Function Not Found

可以在这里找到源代码https://github.com/zevrant/screeps

我有一个由多个 类 实现的接口,当我去调用已实现的接口时,出现以下错误,我不知道为什么。我是一名 java 开发人员,我唯一的打字经验是 Angular,所以我对 TypeScript 的了解有限。

TypeError: spawn.memory.tasks[0].execute 不是函数 在 _.forEach.spawn (../src/main.ts:70:30)

编辑1

记录对象

{"priority":10,"class":"SpawnCreep","outputs":{},"requirements":{},"sourceLocation":{"id":"2bdee70715ebc4e","room":{"name":"W3N7","energyAvailable":14,"energyCapacityAvailable":300,"visual":{"roomName":"W3N7"}},"pos":{"x":27,"y":16,"roomName":"W3N7"},"name":"Spawn1","energy":14,"energyCapacity":300,"spawning":{"name":"0u9tvotgf5cgw4ifhoewivg","needTime":15,"remainingTime":1},"store":{"energy":14},"owner":{"username":"Zevrant"},"my":true,"hits":5000,"hitsMax":5000,"structureType":"spawn"},"storageLocation":{"id":"2bdee70715ebc4e","room":{"name":"W3N7","energyAvailable":14,"energyCapacityAvailable":300,"visual":{"roomName":"W3N7"}},"pos":{"x":27,"y":16,"roomName":"W3N7"},"name":"Spawn1","energy":14,"energyCapacity":300,"spawning":{"name":"0u9tvotgf5cgw4ifhoewivg","needTime":15,"remainingTime":1},"store":{"energy":14},"owner":{"username":"Zevrant"},"my":true,"hits":5000,"hitsMax":5000,"structureType":"spawn"},"creep":{"id":"2bdee70715ebc4e","room":{"name":"W3N7","energyAvailable":14,"energyCapacityAvailable":300,"visual":{"roomName":"W3N7"}},"pos":{"x":27,"y":16,"roomName":"W3N7"},"name":"Spawn1","energy":14,"energyCapacity":300,"spawning":{"name":"0u9tvotgf5cgw4ifhoewivg","needTime":15,"remainingTime":1},"store":{"energy":14},"owner":{"username":"Zevrant"},"my":true,"hits":5000,"hitsMax":5000,"structureType":"spawn"}}

if you store the class instance in the memory, it gets converted into a JSON representation, ie looses all the functions.

您将需要创建一个空的 class 并设置值并调用该函数。

const spawnCreep = new SpawnCreep()

spawn.memory.tasks[0]分配给spawnCreep

并调用 spawnCreep.execute()