如何将robotCall
方法的参数中的回调runRobot
提取到接口中?我已经尝试过
interface RobotCall {
call: ((state: VillageState, memory: string[]) => Robot)
}
但是请继续获取TypeError。这是正在使用的完整功能,我想在其上使用该接口。
export function runRobot(
state: VillageState,
robotCall: ((state: VillageState, memory: string[]) => Robot),
memory?: string[]): void {
for (let turn = 0; ; turn++) {
if (state.parcels.length === 0) {
console.log('='.repeat(5), `${robotCall.name} done in ${turn} turns`, '='.repeat(5));
break;
}
let robot = robotCall(state, memory);
state = state.move(robot.direction);
memory = robot.memory;
}
}