Skip to content

TypeScript: migrate server-side-render package to TS#71383

Open
kushagra-goyal-14 wants to merge 1 commit intoWordPress:trunkfrom
kushagra-goyal-14:try/migrate-server-side-render-to-ts
Open

TypeScript: migrate server-side-render package to TS#71383
kushagra-goyal-14 wants to merge 1 commit intoWordPress:trunkfrom
kushagra-goyal-14:try/migrate-server-side-render-to-ts

Conversation

@kushagra-goyal-14
Copy link
Copy Markdown
Contributor

What?

Part of #67691

Migrating the server-side-render package to TypeScript.
This PR supersedes #70755 as discussed in this PR

Why?

To enhance DX and add type safety.

How?

By porting the code and tests to TypeScript.

Testing Instructions

Typecheck and unit tests.

@kushagra-goyal-14 kushagra-goyal-14 marked this pull request as ready for review August 28, 2025 10:35
@github-actions
Copy link
Copy Markdown

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.

@im3dabasia im3dabasia added [Type] Code Quality Issues or PRs that relate to code quality [Package] Server Side Render /packages/server-side-render labels Aug 28, 2025
Copy link
Copy Markdown
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 suggestions for minor improvements

} );
} )
.catch( ( error ) => {
.catch( ( error: Error ) => {
Copy link
Copy Markdown
Member

@manzoorwanijk manzoorwanijk Sep 5, 2025

Choose a reason for hiding this comment

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

The error is always unknown on runtime and that is how it should be as a type. If it's just have access to error.name, you can add error instanceof Error check before that. Otherwise, you can simply remove this type annotation here.

/**
* External dependencies
*/
import type { ComponentType, ReactNode } from 'react';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we please not import it here? We can directly use React.ComponentType or React.ReactNode without the need for any import

// translators: %s: error message describing the problem
__( 'Error loading block: %s' ),
message
message || 'Unknown error'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be translated

Suggested change
message || 'Unknown error'
message || __( 'Unknown error' )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Another approach would be to get rid of this extra string by not making message optional in ErrorPlaceholderProps and then using message={ error! } in <ErrorResponsePlaceholder />. We can assert that because the description for error mentions "The error message (available when status is 'error').", which is already the case when it's used there.


export function removeBlockSupportAttributes( attributes ) {
export function removeBlockSupportAttributes(
attributes: Record< string, unknown >
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of making an assertion below for attributes?.style, we can type it here

Suggested change
attributes: Record< string, unknown >
attributes: Record< string, unknown > & {
style?: Record< string, unknown >;
}

typography,
...restStyles
} = attributes?.style || {};
} = ( attributes?.style as Record< string, unknown > ) || {};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can then revert this change

Suggested change
} = ( attributes?.style as Record< string, unknown > ) || {};
} = attributes?.style || {};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Server Side Render /packages/server-side-render [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