Currently, I am in the process of converting traditional JavaScript files into TypeScript for use in client-side deployments within SharePoint. Within SharePoint, there are global variables and libraries that we rely on without needing to explicitly load them in our custom scripts. One such example is a global object called _spPageContextInfo. As TypeScript does not recognize this object by default, I am exploring ways to effectively address this issue. Additionally, I am interested in incorporating automated testing into my workflow, so any solution should accommodate this requirement as well. Perhaps using mock object data could be a viable approach?
Thus far, I have managed to make it work by:
const _spPageContextInfo = window['_spPageContextInfo'];
The same approach applies to jQuery since it is already accessible within my SharePoint environment:
const $ = window['$'];
Do you know of a more efficient way to handle these scenarios where during compile time, I need to inform the compiler that these objects will indeed be available when deployed?