简体   繁体   中英

How do I know JavaScript return types automatically for non-primitives/user-defined types and promises?

I'm working with an SDK and I want to go through all the namespaces shown in its API documentation and verify that all the functions return the correct type of object or if the function returns a promise. However, there are way too many functions to try this manually.

I came across ES6 Iterate over class methods and that might work for functions that don't require input variables but many of the functions in the API I want to try out require inputs as well. It seemed like maybe passing in the .js file process it externally using something like Python might be a good idea but I haven't been able to identify a solution yet.

Overall, I would like to be able to compare all the expected return types from the API documentation vs actual return types for the respective functions and put up the differences on an excel sheet for later use.

The first approach you should try is to see if there is a documentation for the SDK/API where you can read and see what the expected return values are. Due to the fact that it is a JavaSvript api, you kind of need that, or need to read through the code yourself, to know what ALL possible return values are.
If the code itself is documented with JSDocs tags, you could check what they are defined to return, something that most IDE's have support to show you during your coding.

JavaScript is a dynamically typed language, IE, a function could basically return anything. So the best way to know what you should expect is to check for documentation!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM