Skip to content

Instantly share code, notes, and snippets.

@wookieb
Last active July 15, 2020 08:12
Show Gist options
  • Save wookieb/72dc73744ca15ed89cb38c112ca8dee8 to your computer and use it in GitHub Desktop.
Save wookieb/72dc73744ca15ed89cb38c112ca8dee8 to your computer and use it in GitHub Desktop.
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