Sprinkle in readonly on array inputs (#1568)

This commit is contained in:
Jaco
2022-06-28 10:52:57 +03:00
committed by GitHub
parent 691a8e9b18
commit 3bc62adf6f
11 changed files with 35 additions and 19 deletions
+1 -1
View File
@@ -16,7 +16,7 @@
* arrayFilter([0, void 0, true, null, false, ''], false); // [0, true, false, '']
* ```
*/
export function arrayFilter <T = unknown> (array: (T | null | undefined)[], allowNulls = true): T[] {
export function arrayFilter <T = unknown> (array: readonly (T | null | undefined)[], allowNulls = true): T[] {
return array.filter((v): v is T =>
v !== undefined &&
(allowNulls || v !== null)
+1 -1
View File
@@ -18,7 +18,7 @@
* arrayFlatten([[1, 2], [3, 4], [5]]); // [1, 2, 3, 4, 5]
* ```
*/
export function arrayFlatten <T> (arrays: T[][]): T[] {
export function arrayFlatten <T> (arrays: readonly T[][]): T[] {
// noop for the single-entry case
if (arrays.length === 1) {
return arrays[0];
+1 -1
View File
@@ -5,7 +5,7 @@
* @name arrayZip
* @description Combines 2 distinct key/value arrays into a single [K, V] array
*/
export function arrayZip <K, V> (keys: K[], values: V[]): [K, V][] {
export function arrayZip <K, V> (keys: readonly K[], values: readonly V[]): [K, V][] {
const result = new Array<[K, V]>(keys.length);
for (let i = 0; i < keys.length; i++) {