You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5 lines
322 B

2 years ago
  1. // 添加小括号,表示 arr 是数组,数组中既有 number 类型,也可以有 string 类型的元素
  2. let arr: (number | string)[] = [1, 3, 'a', 'b']
  3. // 不添加小括号,表示 arr1 既可以是 number 类型,又可以是 string[]
  4. let arr1: number | string[] = ['a', 'b']
  5. let arr2: number | string[] = 123