Skip to content

Instantly share code, notes, and snippets.

@jonjitsu
Created September 5, 2019 14:58
Show Gist options
  • Save jonjitsu/243d3146d32869e3befcdc1de78c3740 to your computer and use it in GitHub Desktop.
Save jonjitsu/243d3146d32869e3befcdc1de78c3740 to your computer and use it in GitHub Desktop.
typescript 1
type Item = {
Foo: string,
Bar: string,
// ...
}
function validate(item: Item): string[] {
const required = ['Foo', ... ]
return required.reduce((errors: string[], field) => {
if (item[field] == null) errors.push(`${field} is required`)
return errors
}, [])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment