Last active
July 15, 2020 08:12
-
-
Save wookieb/72dc73744ca15ed89cb38c112ca8dee8 to your computer and use it in GitHub Desktop.
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
function isComplete(data: any): data is {x: number, y: number, size: number, metadata: any} { | |
return typeof data.x === 'number' && typeof data.y === 'number' && typeof data.size === 'number'; | |
} | |
data.reduce((result, data) => { | |
if (isComplete(data)) { | |
// w tym miejscu ts wie, że "data" ma kształt z type guarda | |
return result.concat([ | |
getColor(data.x, data.y, data.metadata) | |
]) | |
} | |
}, []) | |
// jednak filter też zadziała | |
data.filter(isComplete) | |
.map(x => getColor(data.x, data.y, data.metadata)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment