From 090e1b6568f9459f0b0b195c8f42a1267b2d9a63 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Mon, 18 Sep 2023 13:57:03 +0100 Subject: [PATCH] Prefer not to use destructuring with default values --- packages/govuk-frontend/src/govuk/errors/index.mjs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/govuk-frontend/src/govuk/errors/index.mjs b/packages/govuk-frontend/src/govuk/errors/index.mjs index 20b87887a6..01e2112283 100644 --- a/packages/govuk-frontend/src/govuk/errors/index.mjs +++ b/packages/govuk-frontend/src/govuk/errors/index.mjs @@ -56,15 +56,14 @@ export class ElementError extends GOVUKFrontendError { /** * @param {Element} element - The element in error - * @param {object} options - options + * @param {object} options - Element error options * @param {string} options.componentName - The name of the component throwing the error * @param {string} options.identifier - An identifier that'll let the user understand which element has an error (variable name, CSS selector) * @param {typeof HTMLElement} [options.expectedType] - The type that was expected for the element */ - constructor( - element, - { componentName, identifier, expectedType = HTMLElement } - ) { + constructor(element, { componentName, identifier, expectedType }) { + expectedType = expectedType || HTMLElement + const reason = !element ? `${identifier} not found` : `${identifier} is not an instance of "${expectedType.name}"`