question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Argument of type 'Http' is not assignable to parameter of type 'Http'

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

class RESTClient {
   constructor(@Inject(Http) protected http: Http){
   }
   //Some code
}

@Injectable()
@BaseUrl("https://api.github.com/")
export class ReposService extends RESTClient{
  apiUrl: string = "https://api.github.com/";

  constructor(private _http: Http){
    super(_http)
  }

  @GET("orgs/angular/repos")
  list(){
    return null;
  }
}

Above code is throwing following error:

error TS2345: Argument of type 'Http' is not assignable to parameter of type 'Http'.
  Property '_backend' is protected but type 'Http' is not a class derived from 'Http'.

Expected behavior

Reproduction of the problem

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

macOS Sierra, atom, npm

  • Angular version: 2.0.0

  • Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]

  • Language: TypeScript 1.8.10

  • Node (for AoT issues): node --version = 6.3.0

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
iXHenselcommented, Feb 21, 2017

@vicb This is still an issue. As you wrote above Http is imported from a different location:

probably HTTP is imported from different location ?

Indeed, when using npm link your dependency tree looks like this:

Project
+-- @angular/http@2.1.1
`-- myModule
 `-- @angular/http@2.1.1  extraneous

A solution would be to add @angular/http as peerDependency in myModule. But then when developing myModule IntelliSense would complain about not finding @angular/http.

Is there no workaround for this? I have created this for reproduction.

Edit: Sorry i used a different account back then - I am also st3h3n.

1reaction
st3h3ncommented, Nov 7, 2016

probably HTTP is imported from different location ?

Indeed, when using npm link your dependency tree looks like this:

Project
+-- @angular/http@2.1.1
`-- myModule
  `-- @angular/http@2.1.1  extraneous

A solution would be to add @angular/http as peerDependency in myModule. But then when developing myModule IntelliSense would complain about not finding @angular/http.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Argument of type 'Http' is not assignable to parameter of type ...
Try using HttpClient import {HttpClientModule, HttpClient} from '@angular/common/http'; import {TranslateModule ...
Read more >
Argument of type 'Http' is not assignable to ... - Ionic Forum
Argument of type 'HttpClient' is not assignable to parameter of type 'Http'. Property '_backend' is missing in type 'HttpClient'.
Read more >
Argument of type 'Http' is not assignable to ... - iTecNote
I'm developing an Ionic 2 mobile app and want to use ngx-translate features. Following the tutorial, I'm importing necessary files in app module...
Read more >
Angular | null' is not assignable to parameter of type 'string'
The TypeScript interface for the JSON.parse() function defines a string parameter as the first argument, whereas the interface for localStorage.
Read more >
Type 'Observable<Product[]>' is not assignable to type ...
Btw I want to use HttpClient, not Http, and the mapping should be done automatically by using the get<type>("api/route"); syntax, right?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found