Skip to content

Commit

Permalink
TextInput: fix (declare) InputValidator type in JS Docs
Browse files Browse the repository at this point in the history
TS doesn't know what type we're talking about if it's not
imported. So we have to "import" it in JS Docs e.g. using
@typedef.
  • Loading branch information
ctapobep committed Apr 26, 2024
1 parent 0990d24 commit be91c0a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/TextInput/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import TextInputValidityState from "./TextInputValidityState.js";
import {isFiniteNumber, KeyCode, safeHtml} from "../utils.js"

/**
* @typedef {import("../InputValidator.js").default} InputValidator
*/
export default class TextInput extends HTMLElement {
static #INPUT_ATTRIBUTES = new Set(["autocomplete", "autofocus", "disabled", "max", "maxlength",
"min", "minlength", "name", "pattern", "readonly", "step", "type", "value", "placeholder"
Expand All @@ -23,9 +26,7 @@ export default class TextInput extends HTMLElement {
};
/** @type {string} */
#lastChangedValue;
// @ts-ignore
// It doesn't recognise the type correctly even though we have already specified the type of #validators.
/** @type {InputValidator[]}} */
/** @type {InputValidator[]} */
#validators = [];

connectedCallback() {
Expand All @@ -46,7 +47,6 @@ export default class TextInput extends HTMLElement {
window.removeEventListener("visibilitychange", this.#onVisibilityChange.bind(this), { capture: true });
}

// @ts-ignore
/** @param {InputValidator} validator */
addValidator(validator) {
this.#validators.push(validator);
Expand Down Expand Up @@ -81,7 +81,7 @@ export default class TextInput extends HTMLElement {
return false;
}
this.errorMessage = this.#validityState.errorMessage;
for (const /**@type {InputValidator} */ validator of this.#validators) {
for (const validator of this.#validators) {
const result = validator.validate(this, this.value);
if (!result.isValid) {
this.errorMessage = result.errorMessage;
Expand Down

0 comments on commit be91c0a

Please sign in to comment.