Last active
September 3, 2017 13:38
-
-
Save axxag/0b598263c58915557ff16d9c54b97f72 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Our fruit list | |
const fruitData = fromJS([ | |
{ | |
name: 'blueberry', | |
numberOwned: 10, | |
best: true, | |
}, | |
{ | |
name: 'banana', | |
numberOwned: 0, | |
best: false, | |
}, | |
]) | |
// Function to retrieve the best fruit (which is always the blueberry, of course) | |
const getBestFruit = (fruits: typeof fruitData) => fruits.find(fruit => fruit.get('best')) | |
// Function which calculates the best fruit based on fruit name | |
const isBestFruit = (fruitName:string) => fruitName === 'blueberry' | |
// Lets get our best fruit and start inspecting it! | |
const bestFruit = getBestFruit(fruitData) | |
// Test Case #1 | |
// Should return true, no errors | |
isBestFruit(bestFruit.get('name')) | |
// Test Case #2 | |
// Should return a typescript error, since 'best' is a boolean, not a string | |
isBestFruit(bestFruit.get('best')) | |
// Test Case #3 | |
// Should return a typescript error, since 'worst' does not exist on bestfruit | |
const isWorst = bestFruit.get('worst') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment