Although I've never ventured into the realm of Typescript before, I am intrigued by its concept of "stricter JS". My knowledge on the subject is currently very limited as I am just starting to experiment with it.
Essentially, I have developed my own set of functions for my website - a "core.js" file that is created by merging the files in "core/*.js". Each of these files defines properties on a global window.myLib
object.
Subsequently, every page has its own JS file which manages specific events for that particular page and can access elements from the global window.myLib
.
As a result, each page includes two script files:
<script src="/core.js"></script>
<script src="/js/page_name_here.js"></script>
This setup functions efficiently for me.
I utilize VSCode for development and have configured a "globals.d.ts" file listing the properties and functions defined within the library. This enables Intellisense to offer informative tooltips and hints regarding the content's location.
With a desire to advance further, I intend to transition completely to Typescript and have tsc
compile my JS files.
The initial step involves compiling the library, presently executed on the PHP-side by examining file modification times, concatenating files when required, and sending the outcome to closure-compiler. Is this the correct approach for transitioning to TS?
window.myLib = {}
window.myLib.eventHandlers = require("./core/event-handlers.ts")
window.myLib.AJAX = require("./core/ajax.ts")
// ...
If not, what method is appropriate for compiling a file like this?
Following that, Step 2 entails handling the individual page files. I believe that since I already established the "globals.d.ts" file including definitions for the library functions, I don't need to undertake any special actions for enabling those files to leverage library functions. tsc
should recognize the definitions and utilize them whenever window.myLib
is referenced. Is my assumption accurate, or do I need to reference the core file in some manner?
Any additional guidance beyond these questions would be greatly appreciated. I am eager to embark on this new (to me) journey, though there appears to be quite a significant leap from simply writing JS and letting the browser interpret it to now programming for a compiler!