Return values of Promises are not checked in runtime
See original GitHub issueThis is a:
- Bug Report
Which concerns (not really sure):
- flow-runtime
- babel-plugin-flow-runtime
- flow-runtime-validators
The following code does not raise any errors:
type Person = {
name: string
}
function untrustedEndpoint(id: string): Promise<{ data: Person }> {
return Promise.resolve(null) // <= wrong
}
untrustedEndpoint('id')
Currently we will only get the type assertion error once another function receives the return value as an argument, so a workaround is to:
type Person = {
name: string
}
type Endpoint = { data: Person }
function untrustedEndpoint(id: string): Promise<Endpoint> {
return Promise.resolve(null) // <= wrong
}
function processPersonNameFromEndpoint(response : Endpoint) {
return response.data.name
}
untrustedEndpoint('id').then(processPersonNameFromEndpoint)
Raised by @gcanti at https://github.com/gcanti/io-ts/issues/4#issuecomment-285756198
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How do I check if a JavaScript function returns a Promise?
Call the function, use instanceof let possiblePromise = f1(); let isPromise = possiblePromise instanceof Promise;.
Read more >Javascript: How to access the return value of a Promise object
It's really important to note that the Promise object doesn't return a value, it resolves a value via the then() method. It is...
Read more >Check if a Value is a Promise using JavaScript | bobbyhadz
To check if a value is promise, check if the type of the value is an object and has a property named then...
Read more >Promise.resolve() - JavaScript - MDN Web Docs
The Promise.resolve() method "resolves" a given value to a Promise . If the value is a promise, that promise is returned; if the...
Read more >Detect if Value Is a Promise in Node.js and JavaScript
You can use this behavior to determine whether a given value is a promise. Because promises implement the .then() method, you can check...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We can also skip this check in almost all cases in
async
functions - we’d only need it in the fairly rare case of returning a promise, ok, will add it.I just mean in async function specifically:
This does get a check: