Home Untype function calls may not accept type arguments - Angular 5 http calls
Reply: 1

Untype function calls may not accept type arguments - Angular 5 http calls

nishil bhave
nishil bhave Published in 2018-01-12 14:55:31Z

I'm trying to fetch data from API using interface. Bellow is my temp interface

export interface ITemp {
    id: number,
    name: string,
    age:  number

And below is my HTTP service, where there is a fn getHomedetails, which calls an API.

import {Injectable} from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { ITemp } from "../interfaces/temp";
import { Observable } from "rxjs/Observable";
import 'rxjs/Rx';

export class HttpService{

    baseUrl: String;

        this.http = http;
        this.baseUrl = 'some_url';

    getHomeDetails(): Observable<ITemp>  {
        return this.http.get<ITemp>(this.baseUrl); //problem is here 
        //when mouse is pointed on get<ITemp> it shows "Untype function calls may not accept type arguments"



An interface doesn't get defined. I don't know what I'm doing wrong. And the above syntax is an angular 4.3X syntax. The editor which I've used are the sublime and visual studio.

UncleDave Reply to 2018-01-12 14:57:57Z

Just a guess, but I would imagine this is because you're giving your class-level http a type of any:

Change http:any; to http: HttpClient

A good rule of thumb is to not use any unless you really really have to.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.354283 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO