From ab3d188961f8f173193e494d77853bdad37db9cd Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Mon, 3 Feb 2025 12:45:51 +0000 Subject: [PATCH] Code review feedback --- .../src/govuk/common/configuration.mjs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/govuk-frontend/src/govuk/common/configuration.mjs b/packages/govuk-frontend/src/govuk/common/configuration.mjs index 09a0bc0b15..b69e4f5006 100644 --- a/packages/govuk-frontend/src/govuk/common/configuration.mjs +++ b/packages/govuk-frontend/src/govuk/common/configuration.mjs @@ -149,6 +149,7 @@ export function normaliseString(value, property) { * * @internal * @template {Partial>} ConfigurationType + * @template {[keyof ConfigurationType, SchemaProperty | undefined][]} SchemaEntryType * @param {{ schema?: Schema, moduleName: string }} Component - Component class * @param {DOMStringMap} dataset - HTML element dataset * @returns {ObjectNested} Normalised dataset @@ -163,13 +164,16 @@ export function normaliseDataset(Component, dataset) { ) } - const out = /** @type {ReturnType} */ ({}) + const out = /** @type {ObjectNested} */ ({}) + const entries = /** @type {SchemaEntryType} */ ( + Object.entries(Component.schema.properties) + ) // Normalise top-level dataset ('data-*') values using schema types - for (const entries of /** @type {[keyof ConfigurationType, SchemaProperty | undefined][]} */ ( - Object.entries(Component.schema.properties) - )) { - const [namespace, property] = entries + for (const entry of entries) { + const [namespace, property] = entry + + // Cast the `namespace` to string so it can be used to access the dataset const field = namespace.toString() if (field in dataset) {