Skip to content

Commit

Permalink
remove any type
Browse files Browse the repository at this point in the history
add annotation
  • Loading branch information
ElectronicBlueberry authored and mvdbeek committed Mar 15, 2023
1 parent bd75316 commit 08b4536
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions client/src/utils/pushOrSet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
export function pushOrSet(object: { [index: string | number]: any[] }, key: string | number, value: any) {
/**
* Pushes a value to an array in an object, if the array exists. Else creates a new array containing value.
* @param object Object which contains array
* @param key Key which array is in
* @param value Value to push
*/
export function pushOrSet<T, K extends string | number | symbol>(object: { [key in K]: Array<T> }, key: K, value: T) {
if (key in object) {
object[key].push(value);
object[key]!.push(value);
} else {
object[key] = [value];
}
Expand Down

0 comments on commit 08b4536

Please sign in to comment.