【发布时间】:2022-01-26 11:24:17
【问题描述】:
我想对我的字典的值使用日期管道。所以我尝试了这个。
<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'}}
【问题讨论】:
-
watchlist的类型是什么? -
这是一本字典
-
在打字稿中
Dictionary?还是object?
标签: javascript angular typescript dictionary date-pipe