Skip to content
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

A11y: Add types #19096

Merged
merged 3 commits into from
Dec 13, 2019
Merged

A11y: Add types #19096

merged 3 commits into from
Dec 13, 2019

Conversation

sirreal
Copy link
Member

@sirreal sirreal commented Dec 12, 2019

Description

Part of #18838
Extracted from #18942

Add types to a11y package.

Testing Instructions:

Verify type checking passes:

npm run lint-types

@sirreal sirreal added [Type] Code Quality Issues or PRs that relate to code quality [Package] A11y /packages/a11y labels Dec 12, 2019
document.querySelector( 'body' ).appendChild( container );
// Disable reason: the querySelector + optional chain may make the expression `null`.
// eslint-disable-next-line no-unused-expressions
document.querySelector( 'body' )?.appendChild( container );
Copy link
Member Author

Choose a reason for hiding this comment

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

This may be enough of an edge case that we could use a JSDoc cast:

Suggested change
document.querySelector( 'body' )?.appendChild( container );
/** @type { HTMLBodyElement } */ ( document.querySelector( 'body' ) ).appendChild( container );

The optional chain does seem to be correct, it's possible to have a document with no body:

document.createDocumentFragment().querySelector( 'body' ).appendChild( document.createElement( 'div' ) )
// Uncaught TypeError: Cannot read property 'appendChild' of null

That is an extreme edge case, however 🙂

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops, I thought optional chaining was available already.

This change is blocked on #18939 or an alternative implementation.

}
if ( containerAssertive === null ) {
containerAssertive = addContainer( 'assertive' );
addContainer( 'assertive' );
Copy link
Member Author

Choose a reason for hiding this comment

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

I removed the reassignment of the local variables which seems to serve no purpose here.

@sirreal sirreal marked this pull request as ready for review December 12, 2019 10:00
@sirreal
Copy link
Member Author

sirreal commented Dec 12, 2019

Rebased and feedback addressed.

@sirreal
Copy link
Member Author

sirreal commented Dec 12, 2019

This has some an issue with tsc runs:

packages/a11y/src/index.js:4:22 - error TS2307: Cannot find module '@wordpress/dom-ready'.

4 import domReady from '@wordpress/dom-ready';
                       ~~~~~~~~~~~~~~~~~~~~~~


Found 1 error.

We'll need to figure out how to make tsc aware of other packages, likely along the lines of #18838 (comment)

tsconfig.json Outdated
Comment on lines 23 to 27
"baseUrl": ".",
"paths": {
"@wordpress/*": [ "./packages/*/src" ]
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This fixes the issues with the unfound @wordpress/dom-ready module and doesn't seem to introduce any issues.

Seems sufficient for now.

Copy link
Member

Choose a reason for hiding this comment

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

This fixes the issues with the unfound @wordpress/dom-ready module and doesn't seem to introduce any issues.

Seems sufficient for now.

Related: #18927

Once this is in place, we'll probably have trouble adding types to anything which depends on another package which isn't type-ready (i.e. if there are any errors in the dependency code).

Copy link
Member Author

Choose a reason for hiding this comment

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

we'll probably have trouble adding types to anything which depends on another package which isn't type-ready

Based on my experience here, it's already a problem because tsc can't locate the modules.

Copy link
Member Author

@sirreal sirreal Dec 13, 2019

Choose a reason for hiding this comment

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

Would you prefer to sort that out in #18927 or shall we include it here and merge this?

Copy link
Member

Choose a reason for hiding this comment

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

Would you prefer to sort that out in #18927 or shall we include it here and merge this?

I've merged #18927 if you want to go ahead and rebase it here.

@sirreal
Copy link
Member Author

sirreal commented Dec 13, 2019

I've rebased, this should be ready to land now.

@sirreal sirreal merged commit b3e81ee into master Dec 13, 2019
@sirreal sirreal deleted the add/types-a11y branch December 13, 2019 21:56
@youknowriad youknowriad added this to the Gutenberg 7.2 milestone Jan 6, 2020
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