Skip to content

Instantly share code, notes, and snippets.

@loicdescotte
Last active June 17, 2018 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loicdescotte/2b25b08bd5a12e24b70297f0e9efec43 to your computer and use it in GitHub Desktop.
Save loicdescotte/2b25b08bd5a12e24b70297f0e9efec43 to your computer and use it in GitHub Desktop.
typescript strucural typing
interface HasScore {
score: number;
// also works with functions instead of properties
}
let player = { score: 0 };
function addPointsToScore(player: HasScore, points: number): void {
player.score += points;
}
addPointsToScore(player, 5);
console.log(player.score); //5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment