-
Notifications
You must be signed in to change notification settings - Fork 4.5k
TypeScript: migrate a11y package to TS #70680
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
base: trunk
Are you sure you want to change the base?
TypeScript: migrate a11y package to TS #70680
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
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.
This looks good. I have some minor suggestions for further improvements
Here is the final result of my suggestion
diff --git a/packages/a11y/src/test/index.test.ts b/packages/a11y/src/test/index.test.ts
index 64b2718e54..99cff2204f 100644
--- a/packages/a11y/src/test/index.test.ts
+++ b/packages/a11y/src/test/index.test.ts
@@ -25,16 +25,12 @@ jest.mock( '../shared/filter-message', () => {
} );
describe( 'speak', () => {
- let containerPolite = document.getElementById(
- 'a11y-speak-polite'
- ) as HTMLElement;
- let containerAssertive = document.getElementById(
- 'a11y-speak-assertive'
- ) as HTMLElement;
+ let containerPolite = document.getElementById( 'a11y-speak-polite' );
+ let containerAssertive = document.getElementById( 'a11y-speak-assertive' );
beforeEach( () => {
- containerPolite.textContent = '';
- containerAssertive.textContent = '';
+ containerPolite!.textContent = '';
+ containerAssertive!.textContent = '';
} );
describe( 'on import', () => {
@@ -80,7 +76,7 @@ describe( 'speak', () => {
setup();
containerAssertive = document.getElementById(
'a11y-speak-assertive'
- ) as HTMLElement;
+ );
} );
it( 'should set the textcontent of the polite aria-live region', () => {
@@ -94,18 +90,16 @@ describe( 'speak', () => {
describe( 'when somehow the both containers are not present', () => {
beforeEach( () => {
- containerAssertive.remove();
- containerPolite.remove();
+ containerAssertive?.remove();
+ containerPolite?.remove();
} );
afterEach( () => {
setup();
- containerPolite = document.getElementById(
- 'a11y-speak-polite'
- ) as HTMLElement;
+ containerPolite = document.getElementById( 'a11y-speak-polite' );
containerAssertive = document.getElementById(
'a11y-speak-assertive'
- ) as HTMLElement;
+ );
} );
let containerPolite = document.getElementById( | ||
'a11y-speak-polite' | ||
) as HTMLElement; | ||
let containerAssertive = document.getElementById( | ||
'a11y-speak-assertive' | ||
) as HTMLElement; |
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.
Let us avoid this assertion here and make the other relevant changes.
let containerPolite = document.getElementById( | |
'a11y-speak-polite' | |
) as HTMLElement; | |
let containerAssertive = document.getElementById( | |
'a11y-speak-assertive' | |
) as HTMLElement; | |
let containerPolite = document.getElementById( 'a11y-speak-polite' ); | |
let containerAssertive = document.getElementById( 'a11y-speak-assertive' ); |
) as HTMLElement; | ||
let containerAssertive = document.getElementById( | ||
'a11y-speak-assertive' | ||
) as HTMLElement; | ||
|
||
beforeEach( () => { | ||
containerPolite.textContent = ''; |
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.
Both of these here will need to have non-null assertions
containerPolite.textContent = ''; | |
containerPolite!.textContent = ''; |
} ); | ||
|
||
afterEach( () => { | ||
setup(); | ||
containerAssertive = document.getElementById( | ||
'a11y-speak-assertive' | ||
); | ||
) as HTMLElement; |
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.
) as HTMLElement; | |
); |
containerPolite = document.getElementById( 'a11y-speak-polite' ); | ||
containerPolite = document.getElementById( | ||
'a11y-speak-polite' | ||
) as HTMLElement; |
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.
Apart from this, we will need to use optional chainning inside beforeEach
above.
) as HTMLElement; | |
); |
containerAssertive = document.getElementById( | ||
'a11y-speak-assertive' | ||
); | ||
) as HTMLElement; |
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.
) as HTMLElement; | |
); |
What?
Part of #67691
Migrating the a11y package to TypeScript.
Why?
To enhance DX and add type safety.
How?
By porting the code and tests to TypeScript.
Testing Instructions
Typecheck and unit tests.