Type 'typeof HttpHandler' is not assignable to type
See original GitHub issueI’m submitting a…
[x] Bug report
A bit of context first - I’m trying to set up an application that has dynamic routing where the routes are retrieved from elsewhere (let’s say a RoutingService for now).
I have this app-routing.module.ts so far:
import { NgModule } from '@angular/core';
import { HttpClient, HttpHandler } from '@angular/common/http';
import { ReflectiveInjector } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { RoutingService } from './app-routing.service';
// The line that causes the typescript errors
const injector = ReflectiveInjector.resolveAndCreate([RoutingService, HttpClient, HttpHandler]);
const routingService = injector.get(RoutingService);
@NgModule({
imports: [
RouterModule.forRoot(routingService.getRoutes())
],
exports: [
RouterModule
]
})
export class AppRoutingModule {}
The line with a comment above it seems to be causing the following error from Typescript:
src/app/app-routing.module.ts(7,54): error TS2345: Argument of type '(typeof HttpHandler | typeof HttpClient | typeof RoutingService)[]' is not assignable to parameter of type 'Provider[]'.
[0] Type 'typeof HttpHandler | typeof HttpClient | typeof RoutingService' is not assignable to type 'Provider'.
[0] Type 'typeof HttpHandler' is not assignable to type 'Provider'.
[0] Type 'typeof HttpHandler' is not assignable to type 'FactoryProvider'.
[0] Property 'provide' is missing in type 'typeof HttpHandler'.
The code works fine in the browser but fails the typescript build which stops the whole app being built.
Is there any way to fix these errors?
Or alternatively a more elegant way of retrieving external routes in the module file above?
Thanks
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Angular 2/5. Service with HttpClient makes mistake and doesn ...
Type 'typeof HttpHandler' is not assignable to type 'Provider'. Type 'typeof HttpHandler' is not assignable to type 'ClassProvider'. Property ' ...
Read more >angular/angular - Gitter
Types of property 'providers' are incompatible. Type '{ provide: typeof GameService; useClass: typeof GameService; }[]' is not assignable to type 'Provider[]'.
Read more >Communicating with backend services using HTTP - Angular
The asynchronous method sends an HTTP request, and returns an Observable that emits the requested data when the response is received. The return...
Read more >type 'undefined' is not assignable to type 'string'.ts(2345)
Solution 1: Remove the explicit type definition. Since getPerson already returns a Person with a name, we can use the inferred type. function...
Read more >Argument of type is not assignable to parameter of type 'string ...
Fix Angular Argument of type ' { string; }' is not assignable to parameter of ... Type 'typeof HttpHandler' is not assignable to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
+1
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.