Last active
June 17, 2018 07:38
-
-
Save loicdescotte/2b25b08bd5a12e24b70297f0e9efec43 to your computer and use it in GitHub Desktop.
typescript strucural typing
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
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