Typescript type definition file for desktop IDEs?

Some days ago I was wondering, if there is a Typescript type definition package that has all Scriptable types to ease coding in e.g. Visual Studio Code?

If not, @simonbs how have you told the auto completion in the app the types? If you have made such a type definition file for that, could you please share that?

If you haven’t made such a file or you don’t want to share it, I would write a little script to create it from the online documentation, if I’ve some time to spare.

1 Like

There’s not currently a Typescript package for Visual Studio Code but it sounds like a fun idea. Would you then write the script in Typescript, compile it to JS and run that in Scriptable? Or can a Typescript package work in Visual Studio Code when writing plain JS and not actually Typescript?

I have a file containing all type information for the auto completion. It’s structured to be read by Tern code analysis engine but it might very well be easier to parse than the online documentation. I might be able to share it or parts of it.

On the other hand, if you make something that parses the online documentation, you can quickly update your package when new APIs are added :blush:

A typescript definition file is basically an interface or .h file. Visual Studio Code can read it to give suggestions, code completion, etc. A user could write their code in any form of JS (vanilla, ES6, typescript, coffee script, etc). It would obviously have to be compiled to a form Scriptable can then understand. This is the best explanation I’ve found for what it is and why it’s helpful.

EDIT: Looking at Tern it seems like it’s a very similar concept to what you already have.

Thanks for the responses!

I’ve looked at Tern and it looks like that the type definition file for that one only contains the properties and methods, but no description of those. The Typescript type definition file can also contain a description of which property/function/argument does what. Therefore I will probably go the online documentation route.

A Tern language specification can contain documentation and the one for Scriptable actually does.

I still think that parsing the online documentation would be a fine approach. Then you wouldn’t depend on me to deliver a new specification when new APIs are introduced or existing APIs are updated.

Oh, didn’t see that they can also include documentation. I must have missed that on their website!

Yes, I wouldn’t depend on you, but I think, if you also could publish this type file on the Scriptable website together with the documentation updates, then it would be easier to parse than the documentation itself. Especially if you change the appearance of the documentation, the parser has to be adjusted. But the Tern file stays constant in its layout.

Of course, it is your decision if you want to make the Tern file public :wink:

I’ve now made the parser for the documentation. The last question that remains for me is how I should publish it? On npm as a separate package? On npm as a @types package? But then the end user needs to download it using npm and therefore needs a package.json file and node_modules folder in the iCloud Scriptable folder…

Does anyone have a better idea?

If you want to have a look, you can find it here: