TypeScript 数组 indexOf()方法 indexOf()方法返回数组中可以找到给定元素的第一个索引,如果不存在则返回-1。 语法 array.indexOf(searchElement[,fromIndex]); TypeScript 参数详细信息 searchElement−在数组中要定位的元素。 fromIndex−开始搜索的索引。默认为0,
type arr = Array<string> | Array<number>; type duoArr = Array<arr>; const duoArr: duoArr = [[1], ['a']]; const arr = duoArr[0]; arr.indexOf(arr[0]); //提示:类型“string | number”的参数不能赋给类型“never”的参数。不能将类型“string”分配给类型“never”。 const arr2 =...
type arr = Array<string> | Array<number>; type duoArr = Array<arr>; const duoArr: duoArr = [[1], ['a']]; const arr = duoArr[0]; arr.indexOf(arr[0]); //提示:类型“string | number”的参数不能赋给类型“never”的参数。不能将类型“string”分配给类型“never”。 const arr2 =...