(a: ParamsA, b: ParamsB)
| 86 | } |
| 87 | |
| 88 | function combineParams< |
| 89 | ParamsA extends Params, |
| 90 | ParamsB extends Params, |
| 91 | OutParams extends ParamsA & ParamsB, |
| 92 | >(a: ParamsA, b: ParamsB): OutParams { |
| 93 | /** This function combines two objects, with b overwriting a in |
| 94 | * the case of a clash. **/ |
| 95 | // TODO: Doesn't deal with arrays yet, only deals with nested objects |
| 96 | let out = { ...a } as unknown as OutParams; |
| 97 | |
| 98 | for (let key in b) { |
| 99 | if (b.hasOwnProperty(key)) { |
| 100 | // If key is in both objects and both values are objects, |
| 101 | // then recursively combine them |
| 102 | if ( |
| 103 | typeof b[key] === "object" && |
| 104 | b[key] !== null && |
| 105 | !Array.isArray(b[key]) && |
| 106 | out[key] && |
| 107 | typeof out[key] === "object" && |
| 108 | !Array.isArray(out[key]) |
| 109 | ) { |
| 110 | out[key] = combineParams(out[key], b[key]); |
| 111 | } else { |
| 112 | // @ts-ignore |
| 113 | out[key] = b[key]; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | return out; |
| 118 | } |
no outgoing calls
no test coverage detected