Reputation: 185
Long-time C++ guy, recent web-dev guy. My application has a .js file that returns an object:
define('moduleA', [...], function(...) {
...
return {
propertyA: /*boolean value*/,
...
};
});
The ellipses are irrelevant for this question. Now I have a .ts file where I'm trying to import this Javascript module and reference it in the Typescript code. My Typescript looks something like:
//@ts-ignore
import moduleA from 'moduleA';
export class ModuleB {
...
public someMethod() {
if (moduleA.propertyA) {
...
}
}
...
}
When this Typescript is transpiled, the Require statement at the top is correct, but the transpiled code in 'someMethod' above is:
if (module_a_1.default.propertyA) {
...
}
I don't understand where this 'default' sub-object is coming from. As it is now, an exception is thrown when running because 'propertyA' cannot be referenced on 'undefined'. If the 'default' wasn't there and the transpiled code was:
if (module_a_1.propertyA) {
...
}
Then it should work. I'm guessing this is some rookie mistake with Typescript. Can anyone offer insight? Thanks in advance!
Upvotes: 0
Views: 223