Skip to content

Conversation

@im3dabasia
Copy link
Contributor

What?

Part of: #67691
Migrating the sync package to Typescript.

Why?

Type safety.

@im3dabasia im3dabasia added [Type] Code Quality Issues or PRs that relate to code quality [Packages] Sync /package/sync labels Aug 6, 2025
@im3dabasia im3dabasia marked this pull request as ready for review August 6, 2025 14:44
@github-actions
Copy link

github-actions bot commented Aug 6, 2025

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: im3dabasia <im3dabasia1@git.wordpress.org>
Co-authored-by: manzoorwanijk <manzoorwanijk@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 mentioned this pull request Aug 6, 2025
40 tasks
Copy link
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 great. I just have some suggestions for further improvements.

* @type {Record<string,Record<string,()=>void>>}
*/
const listeners = {};
const listeners: Record< string, Record< string, () => void > > = {};
Copy link
Member

Choose a reason for hiding this comment

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

We can use the handy type alias here

Suggested change
const listeners: Record< string, Record< string, () => void > > = {};
const listeners: Record< string, Record< string, VoidFunction > > = {};

Comment on lines 397 to 408
const signalingConn = map.setIfUndefined(
signalingConns,
url,
// Only this conditional logic to create a normal websocket connection or
// an http signaling connection was added to the constructor when compared
// with the base class.
url.startsWith( 'ws://' ) || url.startsWith( 'wss://' )
( url.startsWith( 'ws://' ) || url.startsWith( 'wss://' )
? () => new SignalingConn( url )
: () => new HttpSignalingConn( url )
: () =>
new HttpSignalingConn(
url
) ) as () => SignalingConn
Copy link
Member

Choose a reason for hiding this comment

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

We can get rid of the assertion at the end like this

map.setIfUndefined<
	SignalingConn | HttpSignalingConn,
	string,
	Map< string, SignalingConn | HttpSignalingConn >
>(...)

buffer.fromBase64( m.data ),
room.key
)
// @ts-ignore
Copy link
Member

Choose a reason for hiding this comment

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

Can we please instead use // @ts-expect-error with a comment explaining why?

Also, if it's about the argument, then I would prefer moving the comment inside the parentheses to apply it appropriately.

// @ts-expect-error
.then( execMessage );

vs

.then(
    // @ts-expect-error
    execMessage
);

Former ignores a wide ranges of TS errors. For example, if then is not a function, it won't error, which is what we probably don't want.

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

Labels

[Packages] Sync /package/sync [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants