-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable type declaration guards #3123
Conversation
1477fce
to
ab7b33d
Compare
2992838
to
cd85627
Compare
ab7b33d
to
09c6ab5
Compare
cd85627
to
39f7ac4
Compare
09c6ab5
to
66911f4
Compare
39f7ac4
to
0988f2c
Compare
66911f4
to
4596100
Compare
0988f2c
to
d9dea28
Compare
4596100
to
11224b3
Compare
d9dea28
to
455a866
Compare
11224b3
to
111ce51
Compare
455a866
to
23abf6b
Compare
111ce51
to
e992320
Compare
23abf6b
to
39b22e6
Compare
e992320
to
7b328b9
Compare
39b22e6
to
349545f
Compare
dde0f63
to
dbf3b90
Compare
c233445
to
68464b9
Compare
68464b9
to
ac7c1c3
Compare
dbf3b90
to
0718c67
Compare
ac7c1c3
to
70bcc52
Compare
70bcc52
to
da882a1
Compare
return this | ||
} | ||
|
||
var $textarea = $module.querySelector('.govuk-js-character-count') | ||
if (!$textarea) { | ||
if (!($textarea instanceof HTMLTextAreaElement)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to allow text inputs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say yes, just as a safety to not break things if someone mounted the component on a markup with an <input>
instead of <textarea>
. I don't think we officially support it (given our template uses a textarea), but it does work.
I'm saying yes with the assumption that it's a matter of turning that if
into if (!($textarea instanceof HTMLTextAreaElement || $textarea instanceof HTMLInputElement))
, though. If it's more complex than that, I think we can stick to <textarea>
and treat it in its own block of work for properly supporting input
in the CharacterCount (both at JS and template level).
Kapture.2023-02-02.at.15.22.00.mp4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is where it gets tricky
File upload, checkbox and radio inputs are also HTMLInputElement
But in terms of guarding the .value
property your example works great 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the following places we've gone further than HTMLElement
:
Character count needs <textarea>
or <input>
lint-types
./src/govuk/components/character-count/character-count.mjs#L65
Checkboxes need <input>
with type="checkbox"
lint-types
./src/govuk/components/checkboxes/checkboxes.mjs#L179
Radios need <input>
with type="radio"
lint-types
./src/govuk/components/radios/radios.mjs#L129
Details needs <details>
to avoid polyfill
lint-types
./src/govuk/components/details/details.mjs#L40
Error summary needs <a>
for links and <input>
(checkbox/radio) for legend .scrollIntoView()
lint-types
./src/govuk/components/error-summary/error-summary.mjs#L114
lint-types
./src/govuk/components/error-summary/error-summary.mjs#L185
Skip link needs <a>
lint-types
./src/govuk/components/skip-link/skip-link.mjs#L14
Tabs need <a>
lint-types
./src/govuk/components/tabs/tabs.mjs#L270
da882a1
to
11d1f13
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say we're good to go on that one, as I don't think any of these changes would be breaking. @36degrees I would appreciate a second look, though, in case we missed a potential breaking case when going through the changes with Colin.
Review component JSDoc types against module and element checks We now prefer `{Element}` type to `{HTMLElement}` to maintain compatibility with `querySelector` but we continue to use `instanceof` to guard types Co-Authored-By: Romaric <romaric.pascal@digital.cabinet-office.gov.uk>
Where empty objects are initially assigned (or merged) the compiler needs to know the final “shape” up front In editors and IDEs this also helps populate tooltip messages during loops etc
11d1f13
to
5c134f9
Compare
Add
instanceof
checks where necessary to unblock type declaration checks in: