Skip to content

Conversation

kushagra-goyal-14
Copy link
Contributor

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.

@t-hamano t-hamano mentioned this pull request Jul 11, 2025
39 tasks
@t-hamano t-hamano added [Type] Code Quality Issues or PRs that relate to code quality [Package] A11y /packages/a11y labels Jul 11, 2025
@kushagra-goyal-14 kushagra-goyal-14 marked this pull request as ready for review July 11, 2025 06:39
Copy link

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: kushagra-goyal-14 <kush123@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@manzoorwanijk manzoorwanijk left a 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;
+                       );
                } );

Comment on lines +28 to +33
let containerPolite = document.getElementById(
'a11y-speak-polite'
) as HTMLElement;
let containerAssertive = document.getElementById(
'a11y-speak-assertive'
) as HTMLElement;
Copy link
Member

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.

Suggested change
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 = '';
Copy link
Member

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

Suggested change
containerPolite.textContent = '';
containerPolite!.textContent = '';

} );

afterEach( () => {
setup();
containerAssertive = document.getElementById(
'a11y-speak-assertive'
);
) as HTMLElement;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
) as HTMLElement;
);

containerPolite = document.getElementById( 'a11y-speak-polite' );
containerPolite = document.getElementById(
'a11y-speak-polite'
) as HTMLElement;
Copy link
Member

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.

Suggested change
) as HTMLElement;
);

containerAssertive = document.getElementById(
'a11y-speak-assertive'
);
) as HTMLElement;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
) as HTMLElement;
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] A11y /packages/a11y [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants