I have a website made in ReactJS. The website calls functions of a library analyzejs generated by another programming language. I can only call functions of this library; I cannot modify much the content of this library.
So far, I have been using the first version of the library: analyzejs-v1.js. To achieve this, in frontend/public/index.html of the website, I have
<head>
<script src="/lib/analyzejs-v1.js"></script>
<!-- <script src="/lib/analyzejs-v2.js"></script> -->
</head>
<body>
<div id="root"></div>
</body>
I also have a type declaration file frontend/src/defines/analyzejs-v1.d.ts as follows:
declare function f1(): string;
declare function f2(): string;
...
As a result, in the code of the website, I could call directly f1() to use analyzejs-v1.js.
Now, I would like to add another version of the library analyzejs-v2.js. In some part of the website, I want to call f1() of analyzejs-v1.js; in some part of the website, I want to call f1() of analyzejs-v2.js. So I guess I need to add namespaces such as v1 and v2 to these different versions to avoid conflict. Then, I will be able to call v1.f1() and v2.f2().
I tried to modify frontend/src/defines/analyzejs-v1.d.ts as follows:
declare namespace v1 {
function f1(): string;
function f2(): string;
...
}
And in the code of the website, I tried to use v1.f1().
The compilation did not raise any error. However, running the website and using features calling v1.f1() returned me an error on v1.f1(): Unhandled Rejection (ReferenceError): v1 is not defined.
Does anyone know how to add a namespace to such a library?