我想使用日期管道作為我字典的值。所以我嘗試了這個。
<div *ngFor="let field of watchlist | keyvalue">
<li *ngIf="field.value && field.key">{{field.key}}: {{field.value | date:'d MMM y'}}
但出現錯誤
Error: src/app/update-watchlist/update-watchlist.component.html:45:76 - error TS2769: No overload matches this call.
Overload 1 of 3, '(value: string | number | Date, format?: string | undefined, timezone?: string | undefined, locale?: string | undefined):
string | null', gave the following error.
Argument of type 'unknown' is not assignable to parameter of type 'string | number | Date'.
Type 'unknown' is not assignable to type 'Date'.
Overload 2 of 3, '(value: null | undefined, format?: string | undefined, timezone?: string | undefined, locale?: string | undefined): null', gave the following error.
Argument of type 'unknown' is not assignable to parameter of type 'null | undefined'.
Type 'unknown' is not assignable to type 'null'.
Overload 3 of 3, '(value: string | number | Date | null | undefined, format?: string | undefined, timezone?: string | undefined, locale?: string | undefined): string | null', gave the following error.
Argument of type 'unknown' is not assignable to parameter of type 'string | number | Date | null | undefined'.
Type 'unknown' is not assignable to type 'Date'.
45 <li *ngIf="field.value && field.key">{{field.key}}: {{field.value | date:'d MMM y'}}
uj5u.com熱心網友回復:
確保field.value是 astring或 anumber或 a Date。它目前被視為unknown.
要做到這一點,您要么必須更好地鍵入,watchlist要么顯式地輸入field.value.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/396187.html
標籤:javascript 有角的 打字稿 字典 日期管
