-
-
Save jonjitsu/243d3146d32869e3befcdc1de78c3740 to your computer and use it in GitHub Desktop.
typescript 1
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
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