diff --git a/packages/govuk-frontend/src/govuk/errors/index.mjs b/packages/govuk-frontend/src/govuk/errors/index.mjs index dc69c4f88c..5ba9941cdb 100644 --- a/packages/govuk-frontend/src/govuk/errors/index.mjs +++ b/packages/govuk-frontend/src/govuk/errors/index.mjs @@ -48,23 +48,20 @@ export class ElementError extends GOVUKFrontendError { name = 'ElementError' /** - * * @overload - * @param {string} messageOrOptions - The error message + * @param {string} message - Element error message */ /** * @overload - * @param {object} messageOrOptions - Element error options - * @param {string} messageOrOptions.componentName - The name of the component throwing the error - * @param {string} messageOrOptions.identifier - An identifier that'll let the user understand which element has an error. This is whatever makes the most sense - * @param {Element | null} [messageOrOptions.element] - The element in error - * @param {string} [messageOrOptions.expectedType] - The type that was expected for the identifier + * @param {ElementErrorOptions} options - Element error options */ - constructor(messageOrOptions) { - /* eslint-disable @typescript-eslint/no-unsafe-member-access */ - let message = '' + /** + * @param {string | ElementErrorOptions} messageOrOptions - Element error message or options + */ + constructor(messageOrOptions) { + let message if (typeof messageOrOptions === 'string') { message = messageOrOptions @@ -78,8 +75,16 @@ export class ElementError extends GOVUKFrontendError { } } - /* eslint-enable @typescript-eslint/no-unsafe-member-access */ - - super(`${message}`) + super(message) } } + +/** + * Element error options + * + * @typedef {object} ElementErrorOptions + * @property {string} componentName - The name of the component throwing the error + * @property {string} identifier - An identifier that'll let the user understand which element has an error. This is whatever makes the most sense + * @property {Element | null} [element] - The element in error + * @property {string} [expectedType] - The type that was expected for the identifier + */