-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better types for Scripting API #489
base: main
Are you sure you want to change the base?
Conversation
…to TD Now ExposedThing and ConsumeThing types are generic and allows as parameters of the different functions only the properties that are defined in the TD.
Thank you for testing @danielpeintner ! Can you give me a little bit more context, |
I simply manually updated |
Ah I see, then the problem is here: const thing = await WoT.consume(td as ThingDescription); Casting to plain ThingDescription type will cause |
I see. The problem is that it is shown as an "error" and I don't think this is very good either from developers point of view. |
One option is to default to My preferred solution is to avoid casting to ThingDescription and let the compiler do its work. However, it seems that the ThingDescription type is a little bit too restrictive and as in the counter example, is not easy to create an already good TD using inline object literals 😢 . |
Scripting API call Nov 20
|
This PR can be considered editorial in the sense that improves artifacts of the main note document. In typescript, Generics can be used to improve the description of a certain API. Here I add generic parameters to ExposedThing and ConsumeThing in order to capture compile-time errors like reading a property that does not exist in the consumed Thing Description or attaching a handler for an action that was not defined in the
ExposeThingInit
. The downside is that it makes the types a little bit more complex.