Skip to content

Commit

Permalink
Split @overload into two (default + string or options)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Oct 19, 2023
1 parent 9639396 commit 5e9fe28
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions packages/govuk-frontend/src/govuk/errors/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*/

0 comments on commit 5e9fe28

Please sign in to comment.