-
Notifications
You must be signed in to change notification settings - Fork 28
[typescript] Use namespace instead of interface for WoT functions #215
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
Comments
A quick note: we could make (or could have made) the API object(s) constructible. That would go well with today's trends and solve the issue. It would also ease the separation of conformance classes. We have played with the idea in the past, i.e. instead of Since we would just create JS objects, the constructors won't have side effects. All the things (bindings) that require a Promise now could be done transparently by the impl when any of the interactions are invoked. Similarly, instead of
Looks good to me. |
I like this approach as well 👍 |
@relu91 the proposal is to change
to
and also wrap all other constructs in it plus removing all I am fine with that. Did you try to out whether it has any consequences to existing implementations/code? If not I like the approach! |
I don't have a strong opinion about constructible API object(s). I think people coming from OOP background would like them more, whereas people from function background would prefer the current definition. Using functions might be safer if in the future, somehow, we came up with the idea to initialize a Answering @danielpeintner, yes that is what I changed. I am not sure that I can submit a PR for a W3C repository... since I am not inside the WG. However, I am totally fine if you do the changes 👍 .
I briefly did some experiments with node-wot I remember that I changed a couple of imports and then it was fine. |
For historical reference (and arguments) see #3. Of course we could have plain object constructors and second phase (asynchronous) initialization. We have played with that, too, and IIRC didn't receive much love. |
Fix #215: make the API entry point a namespace.
I think the intial issue about TypeScript is still not resolved... |
Currently, the
wot-typescript-definition
file export WoT functions as part of the WoT interface. This interface is under the namespace WoT, therefore accessible withWoT.WoT
path. This works well for node.js environments, while it may not work as intended inside browsers or servient runtimes.Following the IDL for the
WoT
interface, those API should be accessed from the global scope as, for example,WoT.consume(..)
. I assume that also runtime scripts (i.e. scripts run by servients) MAY use the same mechanism (instead ofimport
orrequire
). However, the typescript definition does not define a globally scoped variable.Typescript documentation suggests using a namespace to specify a global variable. I made a refactored version of the type-definition here. With that d.ts, vscode (and tsc) correctly identify
WoT
global variable inside node-wot scripts as shown in this tweetI am not sure that this is the intended behavior, therefore I am not creating a PR. However, I'd like to understand whether my suggestion could be an improvement to the current
wot-typescript-definitions
or not.The text was updated successfully, but these errors were encountered: