A. Duff A. Duff - 2 months ago 22
TypeScript Question

Force Typescript to recognize __moduleName

I'm trying to set up a build environment for Angular2 and SystemJs, such that I can import components from external libraries, which are defined like so:

@Component({
moduleId: __moduleName,
selector: 'foo-selector',
templateUrl: 'foo.component.html'
})


I know for sure that this is what I want to use, because it works when I run it. But Typescript compilation fails because it can't recognize
moduleName
. How can I tell Typescript to recognize this, or at least, not to complain about it?

This is with Typescript version 2.1.0-dev.20160915 and
module
is set to
system
in
tsconfig.json

Answer

You can try to add this line to your typings/index.d.ts file:

declare var __moduleName: string;
Comments