Considerations for the Sample Code
The sample code in this guide is written under the following rules. Rewrite the code accordingly when you incorporate it into your web app.
const and let
In the sample code, TypeScript variables are declared as
const and their value cannot be changed later.
If you need to change their values in your app, rewrite the code to declare the variables as
let to avoid errors.
Explicit declaration of types in TypeScript
In the sample code, variable types used in TypeScript are basically written under the following rules.
When you can implicitly declare variables with type inference, the sample code omits variable types. Such variables include argument values passed to APIs.
When you cannot know variable types without checking the reference documentation, the sample code explicitly indicates type information even though it is redundant as a notation. Such variables include those of returned values from APIs and arguments of callback functions. You can omit those variable declarations when you implement the web app.
Promises and callbacks
The Thing-IF SDK supports both of promises and callback functions as implementation methods for non-blocking APIs.
The sample code in this guide basically uses promises. If you use callback functions with the Thing-IF SDK APIs, see the API specification in the JSDoc.
For example, you can rewrite the promise code in Executing Commands using a callback function as below.
For implementing promises, see Use Promise in the tutorial and Using Promises in the Implementation Guidelines section for the Kii Cloud SDK.