codetheweb / tuyapi

🌧 An easy-to-use API for devices that use Tuya's cloud services. Documentation: https://codetheweb.github.io/tuyapi.
MIT License
2.09k stars 342 forks source link

Stricter type checking for parameters #139

Closed codetheweb closed 5 years ago

codetheweb commented 5 years ago

As @unparagoned pointed out, if empty strings are provided for the ID or key, TuyAPI doesn't complain.

This needs to be fixed with stricter type checking, and not just for the constructor arguments. All functions should be checked to ensure their arguments are correctly checked.

Also, I've heard that TypeScript has these kinds of things built in. May want to look into porting TuyAPI to TypeScript.

unparagoned commented 5 years ago

@codetheweb I had a quick play but my knowledge of js is very limited so I only made some changes which should help but someone should properly test them out first. Also I've removed some throw errors since a missing id can now be resolved and all get commands work without a key. So I don't think an error should be thrown on init but there probably should be some check on the functions to make sure the person has run resolveID and/or isn't using set without a key. I really don't understand js well enough when it comes to Promises so decided to not touch the get/set functions.

Edit: Can you let me know how to fix what I've done. I tried to fix all the errors but... https://github.com/codetheweb/tuyapi/pull/141