Skip to content

Instantly share code, notes, and snippets.

@brianlovin
Last active November 9, 2017 03:27
Show Gist options
  • Save brianlovin/ff2fb62ed755a8449d96dfc8c134ff1c to your computer and use it in GitHub Desktop.
Save brianlovin/ff2fb62ed755a8449d96dfc8c134ff1c to your computer and use it in GitHub Desktop.
Flow weirdness
// FILE ONE
type Return = {
content: {
body?: string,
title: string,
}
}
const getThread = (id: string): Return => {
// database.get() returns a promise
return database.get(id)
}
// FILE TWO
// ...
const thread = await getThread(id); // <= the flow error shows up here - see below
const trimmed = thread.content.body.trim() // <= and not here when calling .trim() on a possibly undefined value
// ...
// Flow error:
/*
Promise (This type is incompatible with the expected param of union: type application of class 'Promise' |
type parameter 'T' of await Member 1: type application of calss 'Promise' Error: call of method 'trim'
Method cannot be called on possibly undefined value Member 2: type parameter 'T' of await Error: property
'channelId' property not found in Promise
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment