1let fruits: Array<string>;
2fruits = ['Apple', 'Orange', 'Banana'];
3
4let ids: Array<number>;
5ids = [23, 34, 100, 124, 44];
1// let arr_name, elemType[];
2let list: number[] = [1, 2, 3];
3// Generic array type, Array<elemType>:
4let list: Array<number> = [1, 2, 3];
1//Define an interface to standardize and reuse your object
2interface Product {
3 name: string;
4 price: number;
5 description: string;
6}
7
8let pen: Product = {
9 name: "Pen",
10 price: 1.43,
11 description: "Userful for writing"
12}
13
14let products: Product[] = [];
15products.push(pen);
16//...do other products.push(_) to add more objects...
17console.log(products);
18/* -->
19*[
20* {
21* name: "Pen",
22* price: 1.43,
23* description: "Userful for writing"
24* },
25* ...other objects...
26*]
1const animals = ['cat', 'dog', 'mouse'] as const
2type Animal = typeof animals[number]
3
4// type Animal = 'cat' | 'dog' | 'mouse'