lib.es2023.array.d.ts 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  1. /*! *****************************************************************************
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  4. this file except in compliance with the License. You may obtain a copy of the
  5. License at http://www.apache.org/licenses/LICENSE-2.0
  6. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  7. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  8. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  9. MERCHANTABLITY OR NON-INFRINGEMENT.
  10. See the Apache Version 2.0 License for specific language governing permissions
  11. and limitations under the License.
  12. ***************************************************************************** */
  13. /// <reference no-default-lib="true"/>
  14. interface Array<T> {
  15. /**
  16. * Returns the value of the last element in the array where predicate is true, and undefined
  17. * otherwise.
  18. * @param predicate findLast calls predicate once for each element of the array, in descending
  19. * order, until it finds one where predicate returns true. If such an element is found, findLast
  20. * immediately returns that element value. Otherwise, findLast returns undefined.
  21. * @param thisArg If provided, it will be used as the this value for each invocation of
  22. * predicate. If it is not provided, undefined is used instead.
  23. */
  24. findLast<S extends T>(predicate: (value: T, index: number, array: T[]) => value is S, thisArg?: any): S | undefined;
  25. findLast(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): T | undefined;
  26. /**
  27. * Returns the index of the last element in the array where predicate is true, and -1
  28. * otherwise.
  29. * @param predicate findLastIndex calls predicate once for each element of the array, in descending
  30. * order, until it finds one where predicate returns true. If such an element is found,
  31. * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
  32. * @param thisArg If provided, it will be used as the this value for each invocation of
  33. * predicate. If it is not provided, undefined is used instead.
  34. */
  35. findLastIndex(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): number;
  36. /**
  37. * Returns a copy of an array with its elements reversed.
  38. */
  39. toReversed(): T[];
  40. /**
  41. * Returns a copy of an array with its elements sorted.
  42. * @param compareFn Function used to determine the order of the elements. It is expected to return
  43. * a negative value if the first argument is less than the second argument, zero if they're equal, and a positive
  44. * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.
  45. * ```ts
  46. * [11, 2, 22, 1].toSorted((a, b) => a - b) // [1, 2, 11, 22]
  47. * ```
  48. */
  49. toSorted(compareFn?: (a: T, b: T) => number): T[];
  50. /**
  51. * Copies an array and removes elements and, if necessary, inserts new elements in their place. Returns the copied array.
  52. * @param start The zero-based location in the array from which to start removing elements.
  53. * @param deleteCount The number of elements to remove.
  54. * @param items Elements to insert into the copied array in place of the deleted elements.
  55. * @returns The copied array.
  56. */
  57. toSpliced(start: number, deleteCount: number, ...items: T[]): T[];
  58. /**
  59. * Copies an array and removes elements while returning the remaining elements.
  60. * @param start The zero-based location in the array from which to start removing elements.
  61. * @param deleteCount The number of elements to remove.
  62. * @returns A copy of the original array with the remaining elements.
  63. */
  64. toSpliced(start: number, deleteCount?: number): T[];
  65. /**
  66. * Copies an array, then overwrites the value at the provided index with the
  67. * given value. If the index is negative, then it replaces from the end
  68. * of the array.
  69. * @param index The index of the value to overwrite. If the index is
  70. * negative, then it replaces from the end of the array.
  71. * @param value The value to write into the copied array.
  72. * @returns The copied array with the updated value.
  73. */
  74. with(index: number, value: T): T[];
  75. }
  76. interface ReadonlyArray<T> {
  77. /**
  78. * Returns the value of the last element in the array where predicate is true, and undefined
  79. * otherwise.
  80. * @param predicate findLast calls predicate once for each element of the array, in descending
  81. * order, until it finds one where predicate returns true. If such an element is found, findLast
  82. * immediately returns that element value. Otherwise, findLast returns undefined.
  83. * @param thisArg If provided, it will be used as the this value for each invocation of
  84. * predicate. If it is not provided, undefined is used instead.
  85. */
  86. findLast<S extends T>(
  87. predicate: (value: T, index: number, array: readonly T[]) => value is S,
  88. thisArg?: any,
  89. ): S | undefined;
  90. findLast(
  91. predicate: (value: T, index: number, array: readonly T[]) => unknown,
  92. thisArg?: any,
  93. ): T | undefined;
  94. /**
  95. * Returns the index of the last element in the array where predicate is true, and -1
  96. * otherwise.
  97. * @param predicate findLastIndex calls predicate once for each element of the array, in descending
  98. * order, until it finds one where predicate returns true. If such an element is found,
  99. * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
  100. * @param thisArg If provided, it will be used as the this value for each invocation of
  101. * predicate. If it is not provided, undefined is used instead.
  102. */
  103. findLastIndex(
  104. predicate: (value: T, index: number, array: readonly T[]) => unknown,
  105. thisArg?: any,
  106. ): number;
  107. /**
  108. * Copies the array and returns the copied array with all of its elements reversed.
  109. */
  110. toReversed(): T[];
  111. /**
  112. * Copies and sorts the array.
  113. * @param compareFn Function used to determine the order of the elements. It is expected to return
  114. * a negative value if the first argument is less than the second argument, zero if they're equal, and a positive
  115. * value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.
  116. * ```ts
  117. * [11, 2, 22, 1].toSorted((a, b) => a - b) // [1, 2, 11, 22]
  118. * ```
  119. */
  120. toSorted(compareFn?: (a: T, b: T) => number): T[];
  121. /**
  122. * Copies an array and removes elements while, if necessary, inserting new elements in their place, returning the remaining elements.
  123. * @param start The zero-based location in the array from which to start removing elements.
  124. * @param deleteCount The number of elements to remove.
  125. * @param items Elements to insert into the copied array in place of the deleted elements.
  126. * @returns A copy of the original array with the remaining elements.
  127. */
  128. toSpliced(start: number, deleteCount: number, ...items: T[]): T[];
  129. /**
  130. * Copies an array and removes elements while returning the remaining elements.
  131. * @param start The zero-based location in the array from which to start removing elements.
  132. * @param deleteCount The number of elements to remove.
  133. * @returns A copy of the original array with the remaining elements.
  134. */
  135. toSpliced(start: number, deleteCount?: number): T[];
  136. /**
  137. * Copies an array, then overwrites the value at the provided index with the
  138. * given value. If the index is negative, then it replaces from the end
  139. * of the array
  140. * @param index The index of the value to overwrite. If the index is
  141. * negative, then it replaces from the end of the array.
  142. * @param value The value to insert into the copied array.
  143. * @returns A copy of the original array with the inserted value.
  144. */
  145. with(index: number, value: T): T[];
  146. }
  147. interface Int8Array {
  148. /**
  149. * Returns the value of the last element in the array where predicate is true, and undefined
  150. * otherwise.
  151. * @param predicate findLast calls predicate once for each element of the array, in descending
  152. * order, until it finds one where predicate returns true. If such an element is found, findLast
  153. * immediately returns that element value. Otherwise, findLast returns undefined.
  154. * @param thisArg If provided, it will be used as the this value for each invocation of
  155. * predicate. If it is not provided, undefined is used instead.
  156. */
  157. findLast<S extends number>(
  158. predicate: (
  159. value: number,
  160. index: number,
  161. array: Int8Array,
  162. ) => value is S,
  163. thisArg?: any,
  164. ): S | undefined;
  165. findLast(
  166. predicate: (value: number, index: number, array: Int8Array) => unknown,
  167. thisArg?: any,
  168. ): number | undefined;
  169. /**
  170. * Returns the index of the last element in the array where predicate is true, and -1
  171. * otherwise.
  172. * @param predicate findLastIndex calls predicate once for each element of the array, in descending
  173. * order, until it finds one where predicate returns true. If such an element is found,
  174. * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
  175. * @param thisArg If provided, it will be used as the this value for each invocation of
  176. * predicate. If it is not provided, undefined is used instead.
  177. */
  178. findLastIndex(
  179. predicate: (value: number, index: number, array: Int8Array) => unknown,
  180. thisArg?: any,
  181. ): number;
  182. /**
  183. * Copies the array and returns the copy with the elements in reverse order.
  184. */
  185. toReversed(): Uint8Array;
  186. /**
  187. * Copies and sorts the array.
  188. * @param compareFn Function used to determine the order of the elements. It is expected to return
  189. * a negative value if the first argument is less than the second argument, zero if they're equal, and a positive
  190. * value otherwise. If omitted, the elements are sorted in ascending order.
  191. * ```ts
  192. * const myNums = Uint8Array.from([11, 2, 22, 1]);
  193. * myNums.toSorted((a, b) => a - b) // Uint8Array(4) [1, 2, 11, 22]
  194. * ```
  195. */
  196. toSorted(compareFn?: (a: number, b: number) => number): Uint8Array;
  197. /**
  198. * Copies the array and inserts the given number at the provided index.
  199. * @param index The index of the value to overwrite. If the index is
  200. * negative, then it replaces from the end of the array.
  201. * @param value The value to insert into the copied array.
  202. * @returns A copy of the original array with the inserted value.
  203. */
  204. with(index: number, value: number): Uint8Array;
  205. }
  206. interface Uint8Array {
  207. /**
  208. * Returns the value of the last element in the array where predicate is true, and undefined
  209. * otherwise.
  210. * @param predicate findLast calls predicate once for each element of the array, in descending
  211. * order, until it finds one where predicate returns true. If such an element is found, findLast
  212. * immediately returns that element value. Otherwise, findLast returns undefined.
  213. * @param thisArg If provided, it will be used as the this value for each invocation of
  214. * predicate. If it is not provided, undefined is used instead.
  215. */
  216. findLast<S extends number>(
  217. predicate: (
  218. value: number,
  219. index: number,
  220. array: Uint8Array,
  221. ) => value is S,
  222. thisArg?: any,
  223. ): S | undefined;
  224. findLast(
  225. predicate: (value: number, index: number, array: Uint8Array) => unknown,
  226. thisArg?: any,
  227. ): number | undefined;
  228. /**
  229. * Returns the index of the last element in the array where predicate is true, and -1
  230. * otherwise.
  231. * @param predicate findLastIndex calls predicate once for each element of the array, in descending
  232. * order, until it finds one where predicate returns true. If such an element is found,
  233. * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
  234. * @param thisArg If provided, it will be used as the this value for each invocation of
  235. * predicate. If it is not provided, undefined is used instead.
  236. */
  237. findLastIndex(
  238. predicate: (value: number, index: number, array: Uint8Array) => unknown,
  239. thisArg?: any,
  240. ): number;
  241. /**
  242. * Copies the array and returns the copy with the elements in reverse order.
  243. */
  244. toReversed(): Uint8Array;
  245. /**
  246. * Copies and sorts the array.
  247. * @param compareFn Function used to determine the order of the elements. It is expected to return
  248. * a negative value if the first argument is less than the second argument, zero if they're equal, and a positive
  249. * value otherwise. If omitted, the elements are sorted in ascending order.
  250. * ```ts
  251. * const myNums = Uint8Array.from([11, 2, 22, 1]);
  252. * myNums.toSorted((a, b) => a - b) // Uint8Array(4) [1, 2, 11, 22]
  253. * ```
  254. */
  255. toSorted(compareFn?: (a: number, b: number) => number): Uint8Array;
  256. /**
  257. * Copies the array and inserts the given number at the provided index.
  258. * @param index The index of the value to overwrite. If the index is
  259. * negative, then it replaces from the end of the array.
  260. * @param value The value to insert into the copied array.
  261. * @returns A copy of the original array with the inserted value.
  262. */
  263. with(index: number, value: number): Uint8Array;
  264. }
  265. interface Uint8ClampedArray {
  266. /**
  267. * Returns the value of the last element in the array where predicate is true, and undefined
  268. * otherwise.
  269. * @param predicate findLast calls predicate once for each element of the array, in descending
  270. * order, until it finds one where predicate returns true. If such an element is found, findLast
  271. * immediately returns that element value. Otherwise, findLast returns undefined.
  272. * @param thisArg If provided, it will be used as the this value for each invocation of
  273. * predicate. If it is not provided, undefined is used instead.
  274. */
  275. findLast<S extends number>(
  276. predicate: (
  277. value: number,
  278. index: number,
  279. array: Uint8ClampedArray,
  280. ) => value is S,
  281. thisArg?: any,
  282. ): S | undefined;
  283. findLast(
  284. predicate: (
  285. value: number,
  286. index: number,
  287. array: Uint8ClampedArray,
  288. ) => unknown,
  289. thisArg?: any,
  290. ): number | undefined;
  291. /**
  292. * Returns the index of the last element in the array where predicate is true, and -1
  293. * otherwise.
  294. * @param predicate findLastIndex calls predicate once for each element of the array, in descending
  295. * order, until it finds one where predicate returns true. If such an element is found,
  296. * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
  297. * @param thisArg If provided, it will be used as the this value for each invocation of
  298. * predicate. If it is not provided, undefined is used instead.
  299. */
  300. findLastIndex(
  301. predicate: (
  302. value: number,
  303. index: number,
  304. array: Uint8ClampedArray,
  305. ) => unknown,
  306. thisArg?: any,
  307. ): number;
  308. /**
  309. * Copies the array and returns the copy with the elements in reverse order.
  310. */
  311. toReversed(): Uint8ClampedArray;
  312. /**
  313. * Copies and sorts the array.
  314. * @param compareFn Function used to determine the order of the elements. It is expected to return
  315. * a negative value if the first argument is less than the second argument, zero if they're equal, and a positive
  316. * value otherwise. If omitted, the elements are sorted in ascending order.
  317. * ```ts
  318. * const myNums = Uint8ClampedArray.from([11, 2, 22, 1]);
  319. * myNums.toSorted((a, b) => a - b) // Uint8ClampedArray(4) [1, 2, 11, 22]
  320. * ```
  321. */
  322. toSorted(compareFn?: (a: number, b: number) => number): Uint8ClampedArray;
  323. /**
  324. * Copies the array and inserts the given number at the provided index.
  325. * @param index The index of the value to overwrite. If the index is
  326. * negative, then it replaces from the end of the array.
  327. * @param value The value to insert into the copied array.
  328. * @returns A copy of the original array with the inserted value.
  329. */
  330. with(index: number, value: number): Uint8ClampedArray;
  331. }
  332. interface Int16Array {
  333. /**
  334. * Returns the value of the last element in the array where predicate is true, and undefined
  335. * otherwise.
  336. * @param predicate findLast calls predicate once for each element of the array, in descending
  337. * order, until it finds one where predicate returns true. If such an element is found, findLast
  338. * immediately returns that element value. Otherwise, findLast returns undefined.
  339. * @param thisArg If provided, it will be used as the this value for each invocation of
  340. * predicate. If it is not provided, undefined is used instead.
  341. */
  342. findLast<S extends number>(
  343. predicate: (
  344. value: number,
  345. index: number,
  346. array: Int16Array,
  347. ) => value is S,
  348. thisArg?: any,
  349. ): S | undefined;
  350. findLast(
  351. predicate: (value: number, index: number, array: Int16Array) => unknown,
  352. thisArg?: any,
  353. ): number | undefined;
  354. /**
  355. * Returns the index of the last element in the array where predicate is true, and -1
  356. * otherwise.
  357. * @param predicate findLastIndex calls predicate once for each element of the array, in descending
  358. * order, until it finds one where predicate returns true. If such an element is found,
  359. * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
  360. * @param thisArg If provided, it will be used as the this value for each invocation of
  361. * predicate. If it is not provided, undefined is used instead.
  362. */
  363. findLastIndex(
  364. predicate: (value: number, index: number, array: Int16Array) => unknown,
  365. thisArg?: any,
  366. ): number;
  367. /**
  368. * Copies the array and returns the copy with the elements in reverse order.
  369. */
  370. toReversed(): Int16Array;
  371. /**
  372. * Copies and sorts the array.
  373. * @param compareFn Function used to determine the order of the elements. It is expected to return
  374. * a negative value if the first argument is less than the second argument, zero if they're equal, and a positive
  375. * value otherwise. If omitted, the elements are sorted in ascending order.
  376. * ```ts
  377. * const myNums = Int16Array.from([11, 2, -22, 1]);
  378. * myNums.toSorted((a, b) => a - b) // Int16Array(4) [-22, 1, 2, 11]
  379. * ```
  380. */
  381. toSorted(compareFn?: (a: number, b: number) => number): Int16Array;
  382. /**
  383. * Copies the array and inserts the given number at the provided index.
  384. * @param index The index of the value to overwrite. If the index is
  385. * negative, then it replaces from the end of the array.
  386. * @param value The value to insert into the copied array.
  387. * @returns A copy of the original array with the inserted value.
  388. */
  389. with(index: number, value: number): Int16Array;
  390. }
  391. interface Uint16Array {
  392. /**
  393. * Returns the value of the last element in the array where predicate is true, and undefined
  394. * otherwise.
  395. * @param predicate findLast calls predicate once for each element of the array, in descending
  396. * order, until it finds one where predicate returns true. If such an element is found, findLast
  397. * immediately returns that element value. Otherwise, findLast returns undefined.
  398. * @param thisArg If provided, it will be used as the this value for each invocation of
  399. * predicate. If it is not provided, undefined is used instead.
  400. */
  401. findLast<S extends number>(
  402. predicate: (
  403. value: number,
  404. index: number,
  405. array: Uint16Array,
  406. ) => value is S,
  407. thisArg?: any,
  408. ): S | undefined;
  409. findLast(
  410. predicate: (
  411. value: number,
  412. index: number,
  413. array: Uint16Array,
  414. ) => unknown,
  415. thisArg?: any,
  416. ): number | undefined;
  417. /**
  418. * Returns the index of the last element in the array where predicate is true, and -1
  419. * otherwise.
  420. * @param predicate findLastIndex calls predicate once for each element of the array, in descending
  421. * order, until it finds one where predicate returns true. If such an element is found,
  422. * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
  423. * @param thisArg If provided, it will be used as the this value for each invocation of
  424. * predicate. If it is not provided, undefined is used instead.
  425. */
  426. findLastIndex(
  427. predicate: (
  428. value: number,
  429. index: number,
  430. array: Uint16Array,
  431. ) => unknown,
  432. thisArg?: any,
  433. ): number;
  434. /**
  435. * Copies the array and returns the copy with the elements in reverse order.
  436. */
  437. toReversed(): Uint16Array;
  438. /**
  439. * Copies and sorts the array.
  440. * @param compareFn Function used to determine the order of the elements. It is expected to return
  441. * a negative value if the first argument is less than the second argument, zero if they're equal, and a positive
  442. * value otherwise. If omitted, the elements are sorted in ascending order.
  443. * ```ts
  444. * const myNums = Uint16Array.from([11, 2, 22, 1]);
  445. * myNums.toSorted((a, b) => a - b) // Uint16Array(4) [1, 2, 11, 22]
  446. * ```
  447. */
  448. toSorted(compareFn?: (a: number, b: number) => number): Uint16Array;
  449. /**
  450. * Copies the array and inserts the given number at the provided index.
  451. * @param index The index of the value to overwrite. If the index is
  452. * negative, then it replaces from the end of the array.
  453. * @param value The value to insert into the copied array.
  454. * @returns A copy of the original array with the inserted value.
  455. */
  456. with(index: number, value: number): Uint16Array;
  457. }
  458. interface Int32Array {
  459. /**
  460. * Returns the value of the last element in the array where predicate is true, and undefined
  461. * otherwise.
  462. * @param predicate findLast calls predicate once for each element of the array, in descending
  463. * order, until it finds one where predicate returns true. If such an element is found, findLast
  464. * immediately returns that element value. Otherwise, findLast returns undefined.
  465. * @param thisArg If provided, it will be used as the this value for each invocation of
  466. * predicate. If it is not provided, undefined is used instead.
  467. */
  468. findLast<S extends number>(
  469. predicate: (
  470. value: number,
  471. index: number,
  472. array: Int32Array,
  473. ) => value is S,
  474. thisArg?: any,
  475. ): S | undefined;
  476. findLast(
  477. predicate: (value: number, index: number, array: Int32Array) => unknown,
  478. thisArg?: any,
  479. ): number | undefined;
  480. /**
  481. * Returns the index of the last element in the array where predicate is true, and -1
  482. * otherwise.
  483. * @param predicate findLastIndex calls predicate once for each element of the array, in descending
  484. * order, until it finds one where predicate returns true. If such an element is found,
  485. * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
  486. * @param thisArg If provided, it will be used as the this value for each invocation of
  487. * predicate. If it is not provided, undefined is used instead.
  488. */
  489. findLastIndex(
  490. predicate: (value: number, index: number, array: Int32Array) => unknown,
  491. thisArg?: any,
  492. ): number;
  493. /**
  494. * Copies the array and returns the copy with the elements in reverse order.
  495. */
  496. toReversed(): Int32Array;
  497. /**
  498. * Copies and sorts the array.
  499. * @param compareFn Function used to determine the order of the elements. It is expected to return
  500. * a negative value if the first argument is less than the second argument, zero if they're equal, and a positive
  501. * value otherwise. If omitted, the elements are sorted in ascending order.
  502. * ```ts
  503. * const myNums = Int32Array.from([11, 2, -22, 1]);
  504. * myNums.toSorted((a, b) => a - b) // Int32Array(4) [-22, 1, 2, 11]
  505. * ```
  506. */
  507. toSorted(compareFn?: (a: number, b: number) => number): Int32Array;
  508. /**
  509. * Copies the array and inserts the given number at the provided index.
  510. * @param index The index of the value to overwrite. If the index is
  511. * negative, then it replaces from the end of the array.
  512. * @param value The value to insert into the copied array.
  513. * @returns A copy of the original array with the inserted value.
  514. */
  515. with(index: number, value: number): Int32Array;
  516. }
  517. interface Uint32Array {
  518. /**
  519. * Returns the value of the last element in the array where predicate is true, and undefined
  520. * otherwise.
  521. * @param predicate findLast calls predicate once for each element of the array, in descending
  522. * order, until it finds one where predicate returns true. If such an element is found, findLast
  523. * immediately returns that element value. Otherwise, findLast returns undefined.
  524. * @param thisArg If provided, it will be used as the this value for each invocation of
  525. * predicate. If it is not provided, undefined is used instead.
  526. */
  527. findLast<S extends number>(
  528. predicate: (
  529. value: number,
  530. index: number,
  531. array: Uint32Array,
  532. ) => value is S,
  533. thisArg?: any,
  534. ): S | undefined;
  535. findLast(
  536. predicate: (
  537. value: number,
  538. index: number,
  539. array: Uint32Array,
  540. ) => unknown,
  541. thisArg?: any,
  542. ): number | undefined;
  543. /**
  544. * Returns the index of the last element in the array where predicate is true, and -1
  545. * otherwise.
  546. * @param predicate findLastIndex calls predicate once for each element of the array, in descending
  547. * order, until it finds one where predicate returns true. If such an element is found,
  548. * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
  549. * @param thisArg If provided, it will be used as the this value for each invocation of
  550. * predicate. If it is not provided, undefined is used instead.
  551. */
  552. findLastIndex(
  553. predicate: (
  554. value: number,
  555. index: number,
  556. array: Uint32Array,
  557. ) => unknown,
  558. thisArg?: any,
  559. ): number;
  560. /**
  561. * Copies the array and returns the copy with the elements in reverse order.
  562. */
  563. toReversed(): Uint32Array;
  564. /**
  565. * Copies and sorts the array.
  566. * @param compareFn Function used to determine the order of the elements. It is expected to return
  567. * a negative value if the first argument is less than the second argument, zero if they're equal, and a positive
  568. * value otherwise. If omitted, the elements are sorted in ascending order.
  569. * ```ts
  570. * const myNums = Uint32Array.from([11, 2, 22, 1]);
  571. * myNums.toSorted((a, b) => a - b) // Uint32Array(4) [1, 2, 11, 22]
  572. * ```
  573. */
  574. toSorted(compareFn?: (a: number, b: number) => number): Uint32Array;
  575. /**
  576. * Copies the array and inserts the given number at the provided index.
  577. * @param index The index of the value to overwrite. If the index is
  578. * negative, then it replaces from the end of the array.
  579. * @param value The value to insert into the copied array.
  580. * @returns A copy of the original array with the inserted value.
  581. */
  582. with(index: number, value: number): Uint32Array;
  583. }
  584. interface Float32Array {
  585. /**
  586. * Returns the value of the last element in the array where predicate is true, and undefined
  587. * otherwise.
  588. * @param predicate findLast calls predicate once for each element of the array, in descending
  589. * order, until it finds one where predicate returns true. If such an element is found, findLast
  590. * immediately returns that element value. Otherwise, findLast returns undefined.
  591. * @param thisArg If provided, it will be used as the this value for each invocation of
  592. * predicate. If it is not provided, undefined is used instead.
  593. */
  594. findLast<S extends number>(
  595. predicate: (
  596. value: number,
  597. index: number,
  598. array: Float32Array,
  599. ) => value is S,
  600. thisArg?: any,
  601. ): S | undefined;
  602. findLast(
  603. predicate: (
  604. value: number,
  605. index: number,
  606. array: Float32Array,
  607. ) => unknown,
  608. thisArg?: any,
  609. ): number | undefined;
  610. /**
  611. * Returns the index of the last element in the array where predicate is true, and -1
  612. * otherwise.
  613. * @param predicate findLastIndex calls predicate once for each element of the array, in descending
  614. * order, until it finds one where predicate returns true. If such an element is found,
  615. * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
  616. * @param thisArg If provided, it will be used as the this value for each invocation of
  617. * predicate. If it is not provided, undefined is used instead.
  618. */
  619. findLastIndex(
  620. predicate: (
  621. value: number,
  622. index: number,
  623. array: Float32Array,
  624. ) => unknown,
  625. thisArg?: any,
  626. ): number;
  627. /**
  628. * Copies the array and returns the copy with the elements in reverse order.
  629. */
  630. toReversed(): Float32Array;
  631. /**
  632. * Copies and sorts the array.
  633. * @param compareFn Function used to determine the order of the elements. It is expected to return
  634. * a negative value if the first argument is less than the second argument, zero if they're equal, and a positive
  635. * value otherwise. If omitted, the elements are sorted in ascending order.
  636. * ```ts
  637. * const myNums = Float32Array.from([11.25, 2, -22.5, 1]);
  638. * myNums.toSorted((a, b) => a - b) // Float32Array(4) [-22.5, 1, 2, 11.5]
  639. * ```
  640. */
  641. toSorted(compareFn?: (a: number, b: number) => number): Float32Array;
  642. /**
  643. * Copies the array and inserts the given number at the provided index.
  644. * @param index The index of the value to overwrite. If the index is
  645. * negative, then it replaces from the end of the array.
  646. * @param value The value to insert into the copied array.
  647. * @returns A copy of the original array with the inserted value.
  648. */
  649. with(index: number, value: number): Float32Array;
  650. }
  651. interface Float64Array {
  652. /**
  653. * Returns the value of the last element in the array where predicate is true, and undefined
  654. * otherwise.
  655. * @param predicate findLast calls predicate once for each element of the array, in descending
  656. * order, until it finds one where predicate returns true. If such an element is found, findLast
  657. * immediately returns that element value. Otherwise, findLast returns undefined.
  658. * @param thisArg If provided, it will be used as the this value for each invocation of
  659. * predicate. If it is not provided, undefined is used instead.
  660. */
  661. findLast<S extends number>(
  662. predicate: (
  663. value: number,
  664. index: number,
  665. array: Float64Array,
  666. ) => value is S,
  667. thisArg?: any,
  668. ): S | undefined;
  669. findLast(
  670. predicate: (
  671. value: number,
  672. index: number,
  673. array: Float64Array,
  674. ) => unknown,
  675. thisArg?: any,
  676. ): number | undefined;
  677. /**
  678. * Returns the index of the last element in the array where predicate is true, and -1
  679. * otherwise.
  680. * @param predicate findLastIndex calls predicate once for each element of the array, in descending
  681. * order, until it finds one where predicate returns true. If such an element is found,
  682. * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
  683. * @param thisArg If provided, it will be used as the this value for each invocation of
  684. * predicate. If it is not provided, undefined is used instead.
  685. */
  686. findLastIndex(
  687. predicate: (
  688. value: number,
  689. index: number,
  690. array: Float64Array,
  691. ) => unknown,
  692. thisArg?: any,
  693. ): number;
  694. /**
  695. * Copies the array and returns the copy with the elements in reverse order.
  696. */
  697. toReversed(): Float64Array;
  698. /**
  699. * Copies and sorts the array.
  700. * @param compareFn Function used to determine the order of the elements. It is expected to return
  701. * a negative value if the first argument is less than the second argument, zero if they're equal, and a positive
  702. * value otherwise. If omitted, the elements are sorted in ascending order.
  703. * ```ts
  704. * const myNums = Float64Array.from([11.25, 2, -22.5, 1]);
  705. * myNums.toSorted((a, b) => a - b) // Float64Array(4) [-22.5, 1, 2, 11.5]
  706. * ```
  707. */
  708. toSorted(compareFn?: (a: number, b: number) => number): Float64Array;
  709. /**
  710. * Copies the array and inserts the given number at the provided index.
  711. * @param index The index of the value to overwrite. If the index is
  712. * negative, then it replaces from the end of the array.
  713. * @param value The value to insert into the copied array.
  714. * @returns A copy of the original array with the inserted value.
  715. */
  716. with(index: number, value: number): Float64Array;
  717. }
  718. interface BigInt64Array {
  719. /**
  720. * Returns the value of the last element in the array where predicate is true, and undefined
  721. * otherwise.
  722. * @param predicate findLast calls predicate once for each element of the array, in descending
  723. * order, until it finds one where predicate returns true. If such an element is found, findLast
  724. * immediately returns that element value. Otherwise, findLast returns undefined.
  725. * @param thisArg If provided, it will be used as the this value for each invocation of
  726. * predicate. If it is not provided, undefined is used instead.
  727. */
  728. findLast<S extends bigint>(
  729. predicate: (
  730. value: bigint,
  731. index: number,
  732. array: BigInt64Array,
  733. ) => value is S,
  734. thisArg?: any,
  735. ): S | undefined;
  736. findLast(
  737. predicate: (
  738. value: bigint,
  739. index: number,
  740. array: BigInt64Array,
  741. ) => unknown,
  742. thisArg?: any,
  743. ): bigint | undefined;
  744. /**
  745. * Returns the index of the last element in the array where predicate is true, and -1
  746. * otherwise.
  747. * @param predicate findLastIndex calls predicate once for each element of the array, in descending
  748. * order, until it finds one where predicate returns true. If such an element is found,
  749. * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
  750. * @param thisArg If provided, it will be used as the this value for each invocation of
  751. * predicate. If it is not provided, undefined is used instead.
  752. */
  753. findLastIndex(
  754. predicate: (
  755. value: bigint,
  756. index: number,
  757. array: BigInt64Array,
  758. ) => unknown,
  759. thisArg?: any,
  760. ): number;
  761. /**
  762. * Copies the array and returns the copy with the elements in reverse order.
  763. */
  764. toReversed(): BigInt64Array;
  765. /**
  766. * Copies and sorts the array.
  767. * @param compareFn Function used to determine the order of the elements. It is expected to return
  768. * a negative value if the first argument is less than the second argument, zero if they're equal, and a positive
  769. * value otherwise. If omitted, the elements are sorted in ascending order.
  770. * ```ts
  771. * const myNums = BigInt64Array.from([11n, 2n, -22n, 1n]);
  772. * myNums.toSorted((a, b) => Number(a - b)) // BigInt64Array(4) [-22n, 1n, 2n, 11n]
  773. * ```
  774. */
  775. toSorted(compareFn?: (a: bigint, b: bigint) => number): BigInt64Array;
  776. /**
  777. * Copies the array and inserts the given bigint at the provided index.
  778. * @param index The index of the value to overwrite. If the index is
  779. * negative, then it replaces from the end of the array.
  780. * @param value The value to insert into the copied array.
  781. * @returns A copy of the original array with the inserted value.
  782. */
  783. with(index: number, value: bigint): BigInt64Array;
  784. }
  785. interface BigUint64Array {
  786. /**
  787. * Returns the value of the last element in the array where predicate is true, and undefined
  788. * otherwise.
  789. * @param predicate findLast calls predicate once for each element of the array, in descending
  790. * order, until it finds one where predicate returns true. If such an element is found, findLast
  791. * immediately returns that element value. Otherwise, findLast returns undefined.
  792. * @param thisArg If provided, it will be used as the this value for each invocation of
  793. * predicate. If it is not provided, undefined is used instead.
  794. */
  795. findLast<S extends bigint>(
  796. predicate: (
  797. value: bigint,
  798. index: number,
  799. array: BigUint64Array,
  800. ) => value is S,
  801. thisArg?: any,
  802. ): S | undefined;
  803. findLast(
  804. predicate: (
  805. value: bigint,
  806. index: number,
  807. array: BigUint64Array,
  808. ) => unknown,
  809. thisArg?: any,
  810. ): bigint | undefined;
  811. /**
  812. * Returns the index of the last element in the array where predicate is true, and -1
  813. * otherwise.
  814. * @param predicate findLastIndex calls predicate once for each element of the array, in descending
  815. * order, until it finds one where predicate returns true. If such an element is found,
  816. * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
  817. * @param thisArg If provided, it will be used as the this value for each invocation of
  818. * predicate. If it is not provided, undefined is used instead.
  819. */
  820. findLastIndex(
  821. predicate: (
  822. value: bigint,
  823. index: number,
  824. array: BigUint64Array,
  825. ) => unknown,
  826. thisArg?: any,
  827. ): number;
  828. /**
  829. * Copies the array and returns the copy with the elements in reverse order.
  830. */
  831. toReversed(): BigUint64Array;
  832. /**
  833. * Copies and sorts the array.
  834. * @param compareFn Function used to determine the order of the elements. It is expected to return
  835. * a negative value if the first argument is less than the second argument, zero if they're equal, and a positive
  836. * value otherwise. If omitted, the elements are sorted in ascending order.
  837. * ```ts
  838. * const myNums = BigUint64Array.from([11n, 2n, 22n, 1n]);
  839. * myNums.toSorted((a, b) => Number(a - b)) // BigUint64Array(4) [1n, 2n, 11n, 22n]
  840. * ```
  841. */
  842. toSorted(compareFn?: (a: bigint, b: bigint) => number): BigUint64Array;
  843. /**
  844. * Copies the array and inserts the given bigint at the provided index.
  845. * @param index The index of the value to overwrite. If the index is
  846. * negative, then it replaces from the end of the array.
  847. * @param value The value to insert into the copied array.
  848. * @returns A copy of the original array with the inserted value.
  849. */
  850. with(index: number, value: bigint): BigUint64Array;
  851. }