Last active
August 29, 2015 14:11
-
-
Save rjkip/ae1e6bd77365947e4128 to your computer and use it in GitHub Desktop.
Misleading type incompatibility message
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
[rjkip:/tmp/flowtest]$ flow check | |
/tmp/flowtest/game.js:5:11,16: ?Player | |
This type is incompatible with | |
/tmp/flowtest/player.js:20:18,23: Player | |
Found 1 error |
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
/* @flow */ | |
var Player = require('./player'); | |
class Game { | |
winner: ?Player; | |
constructor() { | |
this.winner = null; | |
} | |
end(winner: Player) { | |
this.winner = winner; | |
} | |
getWinner(): Player { // Return type is the true culprit | |
return this.winner; | |
} | |
} | |
var game = new Game(); | |
game.end(Player.attacker()); |
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
/* @flow */ | |
var attacker = new Player; | |
var defender = new Player; | |
class Player { | |
static attacker(): Player { | |
return attacker; | |
} | |
static defender(): Player { | |
return defender; | |
} | |
/** | |
* @private | |
*/ | |
constructor() {} | |
} | |
module.exports = Player; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment