Skip to content

Instantly share code, notes, and snippets.

@rjkip
Last active August 29, 2015 14:11
Show Gist options
  • Save rjkip/ae1e6bd77365947e4128 to your computer and use it in GitHub Desktop.
Save rjkip/ae1e6bd77365947e4128 to your computer and use it in GitHub Desktop.
Misleading type incompatibility message
[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
/* @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());
/* @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