From 45c147e06d46752ade4184a479b69969a5f394de Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Wed, 19 Jun 2024 13:52:31 -0700 Subject: [PATCH] chore(compartment-mapper): strongly type a function for lulz --- packages/compartment-mapper/src/policy.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/compartment-mapper/src/policy.js b/packages/compartment-mapper/src/policy.js index 362846cf5e..4f6d1a2e7a 100644 --- a/packages/compartment-mapper/src/policy.js +++ b/packages/compartment-mapper/src/policy.js @@ -29,18 +29,24 @@ export const ATTENUATORS_COMPARTMENT = ''; /** * Copies properties (optionally limited to a specific list) from one object to another. - * - * @param {object} from - * @param {object} to - * @param {Array} [list] - * @returns {object} + * @template {Record} T + * @template {Record} U + * @template {Array>} [K=Array] + * @param {T} from + * @param {U} to + * @param {K} [list] + * @returns {Omit & Pick} */ const selectiveCopy = (from, to, list) => { + /** @type {Array>} */ + let props; if (!list) { - list = keys(from); + props = /** @type {Array} */ (keys(from)); + } else { + props = list; } - for (let index = 0; index < list.length; index += 1) { - const key = list[index]; + for (let index = 0; index < props.length; index += 1) { + const key = props[index]; // If an endowment is missing, global value is undefined. // This is an expected behavior if globals are used for platform feature detection to[key] = from[key];