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 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
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 );

This comment has been minimized.

Copy link
@sirreal

sirreal Dec 12, 2019

Author Member

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 🙂

This comment has been minimized.

Copy link
@sirreal

sirreal Dec 12, 2019

Author Member

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' );

This comment has been minimized.

Copy link
@sirreal

sirreal Dec 12, 2019

Author Member

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 Dec 12, 2019
@sirreal sirreal requested review from aduth and youknowriad as code owners Dec 12, 2019
@aduth aduth mentioned this pull request Dec 12, 2019
9 of 67 tasks complete
@sirreal sirreal force-pushed the add/types-a11y branch from 8f27e9d to 992c5e9 Dec 12, 2019
@sirreal

This comment has been minimized.

Copy link
Member Author

sirreal commented Dec 12, 2019

Rebased and feedback addressed.

@sirreal sirreal requested a review from aduth Dec 12, 2019
@sirreal sirreal force-pushed the add/types-a11y branch from 992c5e9 to 6efcba4 Dec 12, 2019
@aduth
aduth approved these changes Dec 12, 2019
@sirreal

This comment has been minimized.

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)

@sirreal sirreal force-pushed the add/types-a11y branch from 6efcba4 to c87f3e2 Dec 12, 2019
"baseUrl": ".",
"paths": {
"@wordpress/*": [ "./packages/*/src" ]
}
Comment on lines 23 to 27

This comment has been minimized.

Copy link
@sirreal

sirreal Dec 12, 2019

Author Member

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

Seems sufficient for now.

This comment has been minimized.

Copy link
@aduth

aduth Dec 12, 2019

Member

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).

This comment has been minimized.

Copy link
@sirreal

sirreal Dec 13, 2019

Author Member

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.

This comment has been minimized.

Copy link
@sirreal

sirreal Dec 13, 2019

Author Member

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

This comment has been minimized.

Copy link
@aduth

aduth Dec 13, 2019

Member

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 sirreal requested a review from aduth Dec 12, 2019
@sirreal sirreal force-pushed the add/types-a11y branch from 12072f3 to 8003ce6 Dec 12, 2019
@sirreal sirreal force-pushed the add/types-a11y branch from 8003ce6 to 5eed3ea Dec 13, 2019
@sirreal

This comment has been minimized.

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
2 checks passed
2 checks passed
pull-request-automation
Details
Travis CI - Pull Request Build Passed
Details
@sirreal sirreal deleted the add/types-a11y branch Dec 13, 2019
@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
Projects
None yet
3 participants
You can’t perform that action at this time.