Last active
November 29, 2016 06:36
-
-
Save dmecke/0df7b329fef6c044ff3b51eed94164b7 to your computer and use it in GitHub Desktop.
The compiler complains about "property 'state' does not exist on type 'Creep'''. It seems main.ts knows about the interface, but not about the implementation. Or is it the other way around?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/Screeps/Creep.ts | |
Creep.prototype.role = function() { | |
return this.memory.role; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// typings/custom/screeps/index.d.ts | |
export interface Creep { | |
role(): string; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/main.ts | |
export function loop() { | |
for (let name in Game.creeps) { | |
if (Game.creeps.hasOwnProperty(name)) { | |
console.log(Game.creeps[name].role()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
// tsconfig.json | |
{ | |
"compilerOptions": { | |
"module": "commonjs", | |
"target": "es6" | |
}, | |
"include": [ | |
"typings/**/*.d.ts", | |
"src/**/*.ts" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment