修复:错误TS2769:没有重载匹配此调用

时间:2020-06-28 02:35:20

标签: angular

我对Angle不熟悉,遇到了这个错误:

ERROR in src/app/inventory/inventory-report-list/inventory-report-list.page.html:26:51 - error TS2769: No overload matches this call.
[ng]       The last overload gave the following error.
[ng]         Argument of type 'Maybe<Maybe<{ __typename?: "InventoryReport" | undefined; } & Pick<InventoryReport, "name" | "id" | "created_at">>[]>' is not assignable to parameter of type 'undefined'.
[ng]           Type 'null' is not assignable to type 'undefined'.
[ng]
[ng]     26               <tr *ngFor="let inventoryReport of (inventoryReports | slice: start: end)" [routerLink]="['./', inventoryReport.id]">
[ng]                                                          ~~~~~~~~~~~~~~~~
[ng]
[ng]       src/app/inventory/inventory-report-list/inventory-report-list.page.ts:7:16
[ng]         7   templateUrl: './inventory-report-list.page.html',
[ng]                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ng]         Error occurs in the template of component InventoryReportListPage.

每次,我都会在模板上添加| slice: start: end部分。一开始会说

[ng] : Compiled successfully.

但是在1-2秒后,该错误会弹出。

这是我的组件。

getInventoryReports() {
    this.isLoading = true;
    
    this.subs.sink = this.inventoryReportsGQL.watch().valueChanges.subscribe(result => {
        this.inventoryReports = result.data.inventoryReports;

        if (this.inventoryReports) {
            this.collectionSize = this.inventoryReports.length;
        }
    });

    this.isLoading = false;
}

这是我的模板:

<ng-container *ngIf="!isLoading">
    <tr *ngFor="let inventoryReport of (inventoryReports | slice: start: end)"
        <th scope="row">{{ inventoryReport.name }}</th>
        <td>{{ inventoryReport.created_at | date:'longDate'}}</td>
    </tr>
</ng-container>

0 个答案:

没有答案