Transitioning from C++ to web development, I find myself facing an issue with my application. There is a .js file that contains the following code snippet which returns an object:
define('moduleA', [...], function(...) {
...
return {
propertyA: /*boolean value*/,
...
};
});
In my new .ts file, I am attempting to import this Javascript module and utilize it in my Typescript code. The relevant snippet of my Typescript code looks like this:
//@ts-ignore
import moduleA from 'moduleA';
export class ModuleB {
...
public someMethod() {
if (moduleA.propertyA) {
...
}
}
...
}
Upon transpilation, the Require statement at the top remains intact, but the transpiled code within 'someMethod' changes to:
if (module_a_1.default.propertyA) {
...
}
I am puzzled by the appearance of the 'default' sub-object. Currently, an exception is thrown during runtime because 'propertyA' is being referenced on 'undefined'. If the transpiled code looked like this instead:
if (module_a_1.propertyA) {
...
}
it would work as expected. I suspect this might be a beginner error in working with Typescript. Can anyone provide insights or suggestions? Your assistance is greatly appreciated!
- Steve