Having a fresh new project in React and Typescript, I need to use a JS Lib developed by my fellow colleagues.
The lib is packaged and added to the project with NPM. The content of the min.js is like:
window.SharedObj=function(e){
...
}
So, this lib is designed to register an instance of SharedObj at the window scope, and I need to retrieve this instance in my top level component (index.tsx).
I've successufully done it this way:
require('path/lib.min.js');
// @ts-ignore
new SharedObj();
if ((window as any).SharedObj) {
ReactDOM.render(
<React.StrictMode>
<App/>
</React.StrictMode>,
document.getElementById('root')
);
}
This works, but it seems wrong to me to ts-ignore and "as any" in order to make this work.
Do you have a better solution ? May I extend the Window definition ?