diff --git a/src/settings/immutability.ts b/src/settings/immutability.ts index 4c900e046..3488ed2fb 100644 --- a/src/settings/immutability.ts +++ b/src/settings/immutability.ts @@ -71,19 +71,47 @@ function loadImmutabilityOverrides( ? overridesSetting : overridesSetting.values ?? []; - const upgraded = raw.map( - ({ type, to, from }) => - ({ - type, - to: typeof to === "string" ? Immutability[to] : to, - from: - from === undefined - ? undefined - : typeof from === "string" - ? Immutability[from] - : from, - }) as ImmutabilityOverrides[number], - ); + const upgraded = raw.map((rawValue) => { + const { type, to, from, ...rest } = rawValue; + const value = { + type, + to: typeof to === "string" ? Immutability[to] : to, + from: + from === undefined + ? undefined + : typeof from === "string" + ? Immutability[from] + : from, + } as ImmutabilityOverrides[number]; + + if (value.type === undefined) { + // eslint-disable-next-line functional/no-throw-statements + throw new Error( + `Override is missing required "type" property. Value: "${JSON.stringify( + rawValue, + )}"`, + ); + } + if (value.to === undefined) { + // eslint-disable-next-line functional/no-throw-statements + throw new Error( + `Override is missing required "to" property. Value: "${JSON.stringify( + rawValue, + )}"`, + ); + } + const restKeys = Object.keys(rest); + if (restKeys.length > 0) { + // eslint-disable-next-line functional/no-throw-statements + throw new Error( + `Override is contains unknown property(s) "${restKeys.join( + ", ", + )}". Value: "${JSON.stringify(rawValue)}"`, + ); + } + + return value; + }); const keepDefault = Array.isArray(overridesSetting) || overridesSetting.keepDefault !== false;