I can't assign a specific object to a variable, although the type is the Right. I have a class called Article.
export class Article {
skuNumber: number;
condition: string;
eanCode: number;
manufacturer: string;
manufacturerIdentifier: string;
title: string;
description: string;
quantity: number;
weight: number;
width: number;
height: number;
depth: number
constructor(
skuNumber: number,
condition: string,
eanCode: number,
manufacturer: string,
manufacturerIdentifier: string,
title: string,
description: string,
quantity: number,
weight: number,
width: number,
height: number,
depth: number
) {
this.skuNumber = skuNumber;
this.condition = condition;
this.eanCode = eanCode;
this.manufacturer = manufacturer;
this.manufacturerIdentifier = manufacturerIdentifier;
this.title = title;
this.description = description;
this.quantity = quantity;
this.weight = weight;
this.width = width
this.height = height;
this.depth = depth
}
}
In another file I populated an Array with some sample data:
import { Article } from "./article";
export const ARTICLES: Array<Article> = [
new Article(
1,
'used',
5060639120949,
'Monster Energy',
'NLZ0930EG',
'Espresso Monster Vanilla + Espresso',
'Ein Espressomischgetränk mit Taurin, Milch und Vanilla-Flavour.',
12,
0.2,
8,
15,
8
),
new Article(
2,
'used',
4018931180179,
'G Data',
'NLZ0930EG',
'G Data Inernet Secuirty Lizenzurkunde',
'Lizenzurkunde der Vollversion von G Data Internet Security.',
2,
0.2,
8,
15,
0
),
new Article(
3,
'used',
4101090000638,
'Staatl. Fachingen',
'NLZ0930EG',
'Mineralwasser Medium',
'Mineralwasser Medium feinperlend und erfrischend.',
57,
1,
10,
25,
10
)
];
Now I want to search a specific object within this Array by
let article: Article = this.articles.filter(article => article.eanCode === eanCodeOfNeededArticle);
But I Always get these error: Type 'Article[]' is missing the following properties from type 'Article': skuNumber, condition, eanCode, manufacturer, and 8 more
Can anyone help me? Thank you very much!
skuNumber: numberbecomesprivate skuNumber: numberand thenthis.skuNumber = skuNumberis generated by the transpiler so you don't have to manually do it for each variable.