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

Convert blob package to TS #62569

Merged
merged 7 commits into from
Jun 14, 2024
Merged

Conversation

up1512001
Copy link
Contributor

@up1512001 up1512001 commented Jun 14, 2024

What?

This PR converts the blob package to TypeScript.

Why?

Ensures package is fully type checked.

How?

  • converted files to .ts
  • explicitly typed variables and functions in index file
  • added @ts-ignore statements to tests that call functions in ways that are not type-compliant

Testing Instructions

  • npm run test:unit -- packages/blob tests pass
  • npm run build:package-types returns a zero exit code

reference PR

Closes #61541

Copy link

github-actions bot commented Jun 14, 2024

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: up1512001 <up1512001@git.wordpress.org>
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>

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

@up1512001
Copy link
Contributor Author

Added type BlobPart = BufferSource | Blob | string; as eslint is giving error of undefined type
The type 'BlobPart' is undefined.eslintjsdoc/no-undefined-types

Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

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

Thanks for picking up this work. All the types need to be removed from JSDoc because they're moving into TypeScript annotations.

Comment on lines 1 to 2
type BlobPart = BufferSource | Blob | string;

Copy link
Member

Choose a reason for hiding this comment

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

We shouldn't need this, it's part of the DOM types.

Suggested change
type BlobPart = BufferSource | Blob | string;

@@ -94,7 +93,11 @@ export function isBlobURL( url ) {
* @param {BlobPart} content File content (BufferSource | Blob | string).
Copy link
Member

Choose a reason for hiding this comment

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

Eslint complained here about the param type, but this has been converted to TypeScript so we need to remove all the types from JSDoc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sirreal please review now I have removed the param type.

@up1512001 up1512001 requested a review from sirreal June 14, 2024 09:54
@sirreal sirreal added the [Type] Code Quality Issues or PRs that relate to code quality label Jun 14, 2024
Use ts-expect-error over ts-ignore
Use toBeUndefined over toBe( undefined )
Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

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

Thanks!

@@ -13,6 +13,8 @@ describe( 'isBlobURL', () => {
} );

it( 'returns false if the url is not defined', () => {
// calling isBlobURL without a URL is not type compliant, so ignore it
// @ts-ignore

This comment was marked as resolved.

Comment on lines 28 to 30
// calling getBlobTypeByURL without a URL is not type compliant, so ignore it
// @ts-ignore
expect( getBlobTypeByURL() ).toBe( undefined );

This comment was marked as resolved.

Comment on lines 55 to 56
window.URL.createObjectURL = createObjectURL;
window.URL.revokeObjectURL = revokeObjectURL;

This comment was marked as resolved.

@sirreal sirreal enabled auto-merge (squash) June 14, 2024 13:01
@sirreal sirreal added the [Package] Blob /packages/blob label Jun 14, 2024
@up1512001
Copy link
Contributor Author

I will note these points for the next TS conversion PRs.
Thanks @sirreal

@sirreal sirreal merged commit 6710fd5 into WordPress:trunk Jun 14, 2024
63 checks passed
@github-actions github-actions bot added this to the Gutenberg 18.6 milestone Jun 14, 2024
patil-vipul pushed a commit to patil-vipul/gutenberg that referenced this pull request Jun 17, 2024
Co-authored-by: jpstevens <jpstevens@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>
Co-authored-by: up1512001 <up1512001@git.wordpress.org>
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.

None yet

2 participants