TypeScript introduces the concept of a declaration file. These files are like header files in C and package specifications in PL/SQL. Declaration files are usually written in files with a
.d.ts file extension. They do not compile, instead, simply describe the functions and variables available in a JS library. They assist in TypeScript code compilation, and with IDE support, developer productivity is enhanced with features like IntelliSense and type-checking. In Code, type-checking is also available in JS with a simple comment at the top of the file:
Vincent changed the paradigm of coding JS in APEX. We could gradually move some of our screen time away from Page Designer, and use mainstream code editors like Visual Studio Code (Code), Atom and Sublime, when working on JS, CSS and PL/SQL code. Without any fanfare, I had suggested and implemented TypeScript support in APEX Nitro that has been available since version 4.0.0-beta. For me, the final piece of the toolchain, would be a TS declaration file for the APEX JS API. Since there aren't any out there, I thought, why not write one? And so I did.
I am very excited about what benefits this might bring to the community and so, going away from my comfort zone, I have decided to make my work public so that fellow APEX developers can have a feel of what it's like working with TypeScript and what benefits it brings. I won't claim to be an expert in TypeScript or the APEX JS API. If you do find errors, please let me know through the usual channels!
Since TypeScript 2.0, declaration files are managed under the DefinitelyTyped project and made available through npm. You can find a list of available declaration files under the organization @types, or from their Github repository. For now, I have published my work at https://github.com/fuzziebrain/orclapex-js with instructions on how to use it in your environment. Eventually though, I'd like to publish this under DefinitelyTyped repository, so keep in touch to be informed of changes.
Some day though, I hope that the APEX JS API would proudly wear the badge: