0

I have a question trying to figuring out what the issue here. I have created a custom Http class, ExtendHttp, which extends the Angular2 Http class and packaged it as a npm module. It compiles and test cases run within the project, but when I import it into other project using the npm module, it will give an error saying:

severity: 'Error' message: 'Argument of type 'ConnectionBackend' is not assignable to parameter of type 'ConnectionBackend'. Types of property 'createConnection' are incompatible. Type '(request: any) => Connection' is not assignable to type '(request: any) => Connection'. Two different types with this name exist, but they are unrelated. Type 'Connection' is not assignable to type 'Connection'. Two different types with this name exist, but they are unrelated. Types of property 'request' are incompatible. Type 'Request' is not assignable to type 'Request'. Two different types with this name exist, but they are unrelated. Types of property 'headers' are incompatible. Type 'Headers' is not assignable to type 'Headers'. Two different types with this name exist, but they are unrelated. Types have separate declarations of a private property 'mayBeSetNormalizedName'.' at: '35,42' source: 'ts'

This is my custom Http Class:

@Injectable()
export class ExtendedHttp extends Http {
    private logger: Logger;
    constructor(_backend: ConnectionBackend, _defaultOptions: RequestOptions,
                private config: ApplicationConfiguration,
                private evtsrv: EventService) {
        super(_backend, _defaultOptions);
        this.logger = new Logger(config.getLoggerConfig());
    }
...
}

This is how I use it in my other project:

@NgModule()
export class CoreModule {
    static forRoot(authzrule: AuthzRule[]): ModuleWithProviders {
    return {
        ngModule: CoreModule,
        providers: [
        { provide: UserSessionStorageService, useClass: UserSessionStorageService },
        {
        provide: Http,
        useFactory: (xhrBackend: ConnectionBackend, requestOptions: RequestOptions,
            config: ApplicationConfiguration, evtservice: EventService) =>
            new ExtendedHttp(xhrBackend, requestOptions, config, evtservice),
        deps: [ConnectionBackend, RequestOptions, ApplicationConfiguration, EventService]
},
3
  • Please post the code of the custom Http class. Commented Feb 23, 2017 at 10:23
  • Please add also the relevant parts of AppModule and the imports you're using Commented Feb 23, 2017 at 10:29
  • So where do you import HttpModule? Please add your TypeScript imports as well. Commented Feb 23, 2017 at 10:48

1 Answer 1

0

After realizing writing the CoreModule on the project where I import the npm module is a bad idea, hence moving the writing of CoreModule back to originate project and package it together with the npm module to resolve the issue.

Thanks Günter Zöchbauer for time & effort, you make realize where I have gone wrong.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.