The call cannot match any overload due to error TS2769

I've been working on a small Angular application:

The file movie.service.ts is structured like this

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { environment } from '../environments/environment';

@Injectable()
export class MovieService {
  constructor(private httpClient: HttpClient) {}

  getMovieList() {
    return this.httpClient.get(environment.gateway + '/movies');
  }

  addMovie(movie: Movie) {
    return this.httpClient.post(environment.gateway + '/movies', movie);
  }

  watchedMovie(movie: Movie) {
    return this.httpClient.put(environment.gateway + '/movies', movie);
  }

  deleteMovie(movie: Movie) {
    return this.httpClient.delete(environment.gateway + '/movies/' + movie.id);
  }
}

export class Movie {
  id: string;
  title: string;
  year: Number;
  watched: boolean;
}

After that, I proceeded to create movie.components.ts:

import { Component, OnInit } from '@angular/core';
import { MovieService, Movie } from '../movie.service';

@Component({
  selector: 'app-movie',
  templateUrl: './movie.component.html',
  styleUrls: ['./movie.component.css']
})
export class MovieComponent implements OnInit {

  activeMovies: Movie[];
  watchedMovies: Movie[];
  todoMessage: string;
  movieTitle: string;
  movieYear: number;

  constructor(private movieService: MovieService) { }

  ngOnInit() {
    this.getAll();
  }

  getAll() {
    this.movieService.getMovieList().subscribe((data: Movie[]) => {
      this.activeMovies = data.filter((a) => !a.watched);
      this.watchedMovies = data.filter((a) => a.watched);
    });
  }

  addMovie() {
    var newMovie : Movie = {
      title: this.movieTitle,
      id: '',
      year: this.movieYear,
      watched: false
    };

    this.movieService.addMovie(newMovie).subscribe(() => {
      this.getAll();
      this.movieTitle = '';
    });
  }

  watchedMovie(movie: Movie) {
    this.movieService.watchedMovie(movie).subscribe(() => {
      this.getAll();
    });
  }

  deleteMovie(movie: Movie) {
    this.movieService.deleteMovie(movie).subscribe(() => {
      this.getAll();
    })
  }
}

However, an error has now surfaced on the following line:

this.movieService.getMovieList().subscribe((data: Movie[]) => {

The error message reads as follows:

✔ Compiled successfully.

    Error: src/app/movie/movie.component.ts:24:48 - error TS2769: No overload matches this call.
      Overload 1 of 5, '(observer?: NextObserver<Object> | ErrorObserver<Object> | CompletionObserver<Object> | undefined): Subscription', gave the following error.
        Argument of type '(data: Movie[]) => void' is not assignable to parameter of type 'NextObserver<Object> | ErrorObserver<Object> | CompletionObserver<Object> 
        Property 'complete' is missing in type '(data: Movie[]) => void' but required in type 'CompletionObserver<Object>'.
      Overload 2 of 5, '(next?: ((value: Object) => void) | undefined, error?: ((error: any) => void) | undefined, complete?: (() => void) | undefined): Subscription', gave the following error.
        Argument of type '(data: Movie[]) => void' is not assignable to parameter of type '(value: Object) => void'.
          Types of parameters 'data' and 'value' are incompatible.
            The 'Object' type is assignable to very few other types. Did you mean to use the 'any' type instead?
              Type 'Object' is missing the following properties from type 'Movie[]': length, pop, push, concat, and 26 more.

    24     this.movieService.getMovieList().subscribe((data: Movie[]) => {
                                                      ~~~~~~~~~~~~~~~~~~~~

      node_modules/rxjs/internal/types.d.ts:64:5
        64     complete: () => void;
               ~~~~~~~~
        'complete' is declared here.

What could be causing this issue or what am I overlooking?

Answer №1

The default type for an HTTP Get request is Observable<Object>. To specify a type for API Calls, you can do it like this.

fetchMovieList() {
    return this.httpClient.get<Film[]>(environment.gateway + '/movies');
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Typescript for directive implementation with isolated scope function bindings

I am currently developing a web application using AngularJS and TypeScript for the first time. The challenge I am facing involves a directive that is supposed to trigger a function passed through its isolate scope. In my application, I have a controller r ...

Mismatch in TypeScript React Intl Redux form types encountered

Currently, I am facing an issue trying to connect my form to Intl and struggling with a TypeScript error. The error seems to disappear when I change injectIntl<any>, but then I'm not sure what exactly needs to be passed there. Can someone please ...

How to assign a custom validator parameter to a form group in Angular

I'm in a situation where I have a form group and need to validate the end date so it is not earlier than the start date. The challenge here lies in accessing specific fields when the form group is not yet declared. dateFormGroup: this.fb.group({ ...

Customizable JSX Attributes for Your TSX/JSX Application

Currently, I am in the process of converting my React project from JavaScript to TypeScript. One challenge I encountered is that TSX React assumes all properties defined in a functional component are mandatory props. // ComponentA.tsx class ComponentA ext ...

Guide to sending a body containing formData inside a key using the fetch API

Whenever I attempt to send an image and a path to the API, it is being sent as [object Object] export async function uploadImageToCDN(image: FormData, directory: string = 'dir'): Promise<any> { const token = await authorizeInApi() const he ...

Common Errors in Angular 2 due to TSLint

I am encountering multiple errors in my code. I am using Angular 2 with TSLint: constructor(http: Http) { this.http = http; --> let currentUser = JSON.parse(localStorage.getItem("currentUser")); this.token = currentUser && currentUser.t ...

Error: global not declared in the context of web3

I've been attempting to integrate Web3 into my Ionic v4 project for some time now. However, I keep encountering errors when I try to serve the project. Specifically, I receive an error message stating that Reference Error: global is not defined. Cre ...

Controlling the DOM with Angular 2

I am currently developing a website in Angular 2. I have successfully implemented a JQuery code that adds 2 input fields and 1 delete button when a custom button is clicked. When the user clicks on the delete button, it removes the inputs by manipulating t ...

Utilizing Google Analytics 4 in a React TypeScript Environment

Currently, there are two options available: Universal Analytics and Google Analytics 4. The reasons why I lean towards using Google Analytics 4: Universal Analytics is set to be retired on July 1, 2023, so it makes sense to start fresh with Google Analyt ...

Leveraging vue-devtools in combination with the composition-api while implementing a render function (such as JSX)

Ever since I made the transition to utilizing the composition-api and incorporating a render function (primarily leveraging JSX with TypeScript for type safety within the template), I've encountered an issue where vue-devtools cannot inspect the compu ...

Combining numerous interfaces into a unified interface in Typescript

I'm struggling to comprehend interfaces in Typescript, as I am facing difficulty in getting them to function according to my requirements. interface RequestData { [key: string]: number | string | File; } function makeRequest(data: RequestData) { ...

How can TypeScript and MobX work together using Set()?

I'm encountering errors while trying to implement Set() in my Grocery Shopping app using MobX with TypeScript. I have a simple setup with defined types in types.ts: types.ts export type Item = { name: string; instock: number; price: number; }; ...

A notification pop-up will only appear the first time after sending a repeated action

When testing my snackBar functionality by inputting incorrect user credentials multiple times and submitting the form, I encountered an issue. The snackBar only appears the first time, not every time an error or success message is dispatched. Below is the ...

What is the process for enabling the isolatedModules=true option when creating a package?

When exporting all the classes from my package in a file, I use lines similar to the following: export {default as BoundList, IBoundListOption, TBoundListFilterFn} from './list/BoundList'; This generates errors like: TS1205: Cannot re-export a ...

Struggling with implementing a simple Edit Modal feature in Angular 8

While I am familiar with Asp.Net MVC Views and the use of Modals, my experience in Angular and Bootstrap 4 has presented a challenge. Creating a Modal to create an employee object is straightforward, but editing that object within a Modal is proving diffic ...

Guide to customizing the layout preview specifically for certain components in Storybook, without affecting all components

Currently working on my storybook project and facing an issue. I'm aiming to have the layout centered in the preview section. I attempted export const parameters = { layout: 'centered', }; in the .storybook/preview.js file However, this c ...

The Angular directive ng-if does not function properly when trying to evaluate if array[0] is equal to the string value 'Value'

In my code, I want to ensure that the icon is only visible if the value at array index 0 is equal to 'Value': HTML <ion-icon *ngIf="allFamily[0] === 'Value'" class="checkas" name="checkmark"></ion-icon> TS allFamily = [ ...

The typings for object properties in Typescript

I recently encountered a function call in my code: var myVar = myFunction({ property: 'prop', functionProperty() { console.log(this.property); }, functionProperty2() { this.functionProperty(); } }); I' ...

Avoiding loading certain images within an *ngFor loop

Is it possible to control the loading of images within an *ngFor loop in Angular? Load image with index X first Fire a function once all other images have loaded The goal is to prioritize the display of important images while optimizing bandwidth usage. ...

The hierarchy of precedence when using the TypeScript Type Assertion operator

Is it necessary to wrap the js-ternary operator with 'as' Type Assertion? ios ? TouchableOpacity : View as React.ElementType Will it automatically use the result of '?:' since it comes first? Or would a better implementation be: (ios ...