Array type definition

This is the third day of my participation in the More text Challenge. For details, see more text Challenge

Normal array type definitions

1. The number type can be written directly or defined by itself

const numberArr = [1.2.3];
const numberArr2 : number[] = [1.2.3];
Copy the code

2. Type string

const stringArr: string[] = ["a"."b"."c"];

Copy the code

3. You can define any type

const undefinedArr: undefined[] = [undefined.undefined];

Copy the code

4. The elements of an array have multiple types

const arr: (number | string) [] = [1."string".2];
Copy the code

The definition of an object type in an array

Use type aliases to start with the type keyword

type lady  = { name : string , age : Number}
const xiaoJieJies: lady[] = [
    { name: "Liu ying".age: 18 },
    { name: "Xie Bigfoot".age: 28},];/* Can be defined as a class */
  class Madam {
    name: string;
    age: number;
  }
  
  const xiaoJieJie2s: Madam[] = [
    { name: "Liu ying".age: 18 },
    { name: "Xie Bigfoot".age: 28},];Copy the code