Reputation: 90863
Currently TypeScript allows me to do something like this:
async function getSomething():Promise<Something> {
// ...
}
Then later:
const myObject = getSomething();
Then later when I try to use myObject
it gives strange errors.
What I'm wondering is - is there any way to make TypeScript display an error when I get promise without await
? I couldn't find any flag for this but maybe I missed it.
Upvotes: 0
Views: 81
Reputation: 1014
Simply type your object:
const myObject: Something = getSomething(); // error, it returns Promise<Something>
const myObject: Something = await getSomething(); // works, it returns Something
Upvotes: 0