我正在尝试从 json 服务器列出到 table

I'm traying to list from json server to a table

尝试在订阅中声明 d 时出现错误

这是我的服务

public apiUrl = 'http://localhost:3000/';

constructor(public http: HttpClient) {}

KayitListele() {
 return this.http.get(this.apiUrl + 'kayitlar');
}

来自组件的ts文件,函数列表

KayitListele() {
 this.servis.KayitListele().subscribe((d: Kayit[]) => {
  this.kayitlar = d;
 });
}

错误信息

No overload matches this call.
  Overload 1 of 5, '(observer?: PartialObserver<Object>): Subscription', gave the following error.
    Argument of type '(d: Kayit[]) => void' is not assignable to parameter of type 'PartialObserver<Object>'.
      Property 'complete' is missing in type '(d: Kayit[]) => void' but required in type 'CompletionObserver<Object>'.
  Overload 2 of 5, '(next?: (value: Object) => void, error?: (error: any) => void, complete?: () => void): Subscription', gave the following error.
    Argument of type '(d: Kayit[]) => void' is not assignable to parameter of type '(value: Object) => void'.
      Types of parameters 'd' 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 'Kayit[]': length, pop, push, concat, and 26 more.ts(2769)
types.d.ts(73, 5): 'complete' is declared here.

我正在学习一门课程,在遇到此错误后,我编写了完全相同的代码,但仍然遇到相同的错误。

像下面这样修改您的服务方法,它应该可以工作。

KayitListele(): Observable<Kayit[]> {
    return this.http.get<Kayit[]>(this.apiUrl + 'kayitlar');
}

当您使用该方法时,您是在说这是我期望的 return 类型,因此在这种情况下,也在您的服务方法中明确声明相同的类型。