Skip to content

Instantly share code, notes, and snippets.

@aherve
Last active December 7, 2016 13:21
Show Gist options
  • Select an option

  • Save aherve/847e01103e90349b6b14b0dd8553125d to your computer and use it in GitHub Desktop.

Select an option

Save aherve/847e01103e90349b6b14b0dd8553125d to your computer and use it in GitHub Desktop.
async function notSure (userId: string | null): Promise<null | User> {
if (!userId) { return null } // e.g. return void
const user = await User.findById(userId) // this return the result of the promise of findById
if (user) { return user }
throw 'User not found'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment