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

Blob: Add types #19092

Merged
merged 2 commits into from
Dec 12, 2019
Merged

Blob: Add types #19092

merged 2 commits into from
Dec 12, 2019

Conversation

sirreal
Copy link
Member

@sirreal sirreal commented Dec 12, 2019

Description

Part of #18838
Extracted from #18942

Add types to blob 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] Blob /packages/blob labels Dec 12, 2019
@@ -3,6 +3,9 @@
*/
const { createObjectURL, revokeObjectURL } = window.URL;

/**
* @type {{[key: string]: File|undefined}}
Copy link
Member Author

Choose a reason for hiding this comment

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

Initially, my editor ignored the | undefined part of this type and the following one. Adding explicit strictNullChecks to the tsconfig restored it.

@@ -27,7 +30,7 @@ export function createBlobURL( file ) {
*
* @param {string} url The blob URL.
*
* @return {?File} The file for the blob URL.
* @return {File|undefined} The file for the blob URL.
Copy link
Member Author

Choose a reason for hiding this comment

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

{?File} is a nullable type in JSDoc, equivalent to File | null, which isn't accurate.

Copy link
Member

Choose a reason for hiding this comment

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

{?File} is a nullable type in JSDoc, equivalent to File | null, which isn't accurate.

Yeah, I think you'll find a lot of examples like this in the codebase, where nullable type is used incorrectly as interchangeable with "optional" or "possibly undefined".

@@ -12,6 +12,7 @@

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"strictNullChecks": true,
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 should be enabled via strict, but I some Type | undefined types didn't seem to be handled correctly. Adding this seems to fix the issue.

I wonder if strict + noImplicitAny results in odd behavior.

@sirreal sirreal marked this pull request as ready for review December 12, 2019 09:30
@sirreal sirreal requested a review from aduth as a code owner December 12, 2019 09:30
@sirreal sirreal merged commit 96ab640 into master Dec 12, 2019
@sirreal sirreal deleted the add/types-blob branch December 12, 2019 21:38
@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] Blob /packages/blob [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