在17号角,我用了
@for (notification of notifications; track notification) {
<i>{{notification.quotationId}}</i>
}
但在WebStorm中,我得到了警告
未解析的变量quotationID
在TypeScrip中,属性notifications
的类型被设置为PendingQuotations
,其为:
export type PendingQuotations = {
quotationId: number,
sender: string,
date: string
}[]
为什么我会收到这个警告?
下面是我设置该属性的方式:
export class HeaderComponent implements OnInit {
public notifications?: PendingQuotations;
constructor(private generalService: GeneralService) { }
ngOnInit(): void {
this.$getNotifications().subscribe((pendingQuotations: PendingQuotations) => {
if (pendingQuotations.length > 0) {
this.notifications = pendingQuotations;
}
});
}
$getNotifications(): Observable<PendingQuotations> {
return this.generalService.get<Response>('/quotation/pending-quotations')
.pipe(
map((res: Response) => res.messages[0] as unknown as PendingQuotations)
);
}
}
这是res
的值:
{
"code": "PENDING_QUOTATIONS",
"status": "OK",
"timestamp": "13.01.2024, 14:33:24",
"messages": [
[
{
"id": 1,
"quotationId": 2,
"receiver": "receiver@example.com",
"sender": "sender@example.com",
"date": "2024-01-13T09:27:59.256+00:00"
}
],
"I am a string"
],
"token": null
}