You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Improve typing (#2055)
This commit is contained in:
committed by
GitHub
parent
95e7a76ba9
commit
f8097221e6
36
src/utils.ts
36
src/utils.ts
@@ -90,23 +90,20 @@ export function removeElement<T>(
|
||||
array: T[],
|
||||
fn: (t: T, i?: number, a?: T[]) => boolean,
|
||||
reverse?: boolean,
|
||||
) {
|
||||
let i;
|
||||
let removed;
|
||||
): boolean {
|
||||
let i: number;
|
||||
if (reverse) {
|
||||
for (i = array.length - 1; i >= 0; i--) {
|
||||
if (fn(array[i], i, array)) {
|
||||
removed = array[i];
|
||||
array.splice(i, 1);
|
||||
return removed;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < array.length; i++) {
|
||||
if (fn(array[i], i, array)) {
|
||||
removed = array[i];
|
||||
array.splice(i, 1);
|
||||
return removed;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -276,31 +273,6 @@ export function deepSortedObjectEntries(obj: any): [string, any][] {
|
||||
return pairs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy properties from one object to another.
|
||||
*
|
||||
* All enumerable properties, included inherited ones, are copied.
|
||||
*
|
||||
* This is approximately equivalent to ES6's Object.assign, except
|
||||
* that the latter doesn't copy inherited properties.
|
||||
*
|
||||
* @param {Object} target The object that will receive new properties
|
||||
* @param {...Object} source Objects from which to copy properties
|
||||
*
|
||||
* @return {Object} target
|
||||
*/
|
||||
export function extend(...restParams) {
|
||||
const target = restParams[0] || {};
|
||||
for (let i = 1; i < restParams.length; i++) {
|
||||
const source = restParams[i];
|
||||
if (!source) continue;
|
||||
for (const propName in source) { // eslint-disable-line guard-for-in
|
||||
target[propName] = source[propName];
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inherit the prototype methods from one constructor into another. This is a
|
||||
* port of the Node.js implementation with an Object.create polyfill.
|
||||
|
||||
Reference in New Issue
Block a user