I am facing a major issue while transitioning to ES6 imports and TypeScript in my Angular 1 application. The problem arises with angular injection causing many ES6 imports to be unused. Let me illustrate this with an example:
Service-
export class MyService {
public doStuff() {}
}
Controller-
import {MyService} from './service';
export class MyController {
public constructor(private MyService: MyService) {MyService.doStuff();}
}
Even if I try renaming the import using as
, the issue persists.
The crux of the problem is that the compiler does not detect the usage of the MyService
import! Hence, the compiled systemjs
code omits it-
System.register('myController', [], function() { ... });
To work around this, I could refactor the methods on MyService
to be static and avoid injecting it through angular. For instance:
import {MyService} from './service';
export class MyController {
public constructor() {MyService.doStuff();}
}
However, we are constrained by time and cannot pursue this approach right now. Our goal is to gradually refactor towards it, but currently, time is of the essence.
How can I compel systemjs
to include these imports?