错误 TS2769:没有与此调用匹配的重载。 (错误在task-view.component.ts) line= .subscribe((lists: List[]) => this.lists = lists);

error TS2769: No overload matches this call. (error is in task-view.component.ts) line= .subscribe((lists: List[]) => this.lists = lists);

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 '(lists: List[]) => List[]' is not assignable to parameter of type 'NextObserver<Object> | ErrorObserver<Object> | CompletionObserver<Object> | 
undefined'.
      Property 'complete' is missing in type '(lists: List[]) => List[]' 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 '(lists: List[]) => List[]' is not assignable to parameter of type '(value: Object) => void'.
      Types of parameters 'lists' 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 'List[]': length, pop, push, concat, and 26 more.

20       .subscribe((lists: List[]) => this.lists = lists);
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

任务-view.component.ts:

import { Component, OnInit } from '@angular/core';
import List from 'src/app/models/list';
import Task from 'src/app/models/task';
import { TaskService } from 'src/app/task.service';

@Component({
  selector: 'app-task-view',
  templateUrl: './task-view.component.html',
  styleUrls: ['./task-view.component.scss'],
})
export class TaskViewComponent implements OnInit {
  lists: List[] = [];
  tasks: Task[] = [];

  constructor(private taskService: TaskService) {}

  ngOnInit(): void {
    this.taskService
      .getLists()
      .subscribe((lists: List[]) => this.lists = lists);
  }
}

task.service.ts

import { WebService } from './web.service';
import Task from './models/task'

@Injectable({
  providedIn: 'root',
})
export class TaskService {
  constructor(private webService: WebService) {}
  getLists() {
    return this.webService.get('lists');
  }

  createList(title: string) {
    return this.webService.post('lists', { title });
  }

  getTasks(listId: string) {
    return this.webService.get(`lists/${listId}/tasks`);
  }

  createTasks(listId: string, title: string) {
    return this.webService.post(`lists/${listId}/tasks`, { title });
  }

  deleteList(listId: string) {
    return this.webService.delete(`lists/${listId}`);
  }

  deleteTask(listId: string, taskId: string) {
    return this.webService.delete(`lists/${listId}/tasks/${taskId}`);
  }

  setCompleted(listId: string, task: Task ) {
    return this.webService.patch(`lists/${listId}/tasks/${task._id}`, {completed: !task.completed});
  }
}

web.service.ts:

import { Injectable } from '@angular/core';
import {HttpClient} from "@angular/common/http";


@Injectable({
  providedIn: 'root'
})
export class WebService {
  readonly ROOT_URL;
  constructor( private http: HttpClient) {
    this.ROOT_URL = "http://localhost:3000" ;
   }

   get(uri: string) {
     return this.http.get(`${this.ROOT_URL}/$(uri)`);
   }

   post(uri: string, payload: Object) {
    return this.http.post(`${this.ROOT_URL}/$(uri)`, payload );
  }

  patch(uri: string, payload: Object) {
    return this.http.patch(`${this.ROOT_URL}/$(uri)`, payload );
  }

  delete(uri: string) {
    return this.http.delete(`${this.ROOT_URL}/$(uri)`);
  }
}

对于字符串插值,您应该使用 ${uri} 而不是 $(uri)