-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Migrate sync package to TypeScript #71099
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
base: trunk
Are you sure you want to change the base?
Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
manzoorwanijk
left a comment
There was a problem hiding this 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 > > = {}; |
There was a problem hiding this comment.
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
| const listeners: Record< string, Record< string, () => void > > = {}; | |
| const listeners: Record< string, Record< string, VoidFunction > > = {}; |
| 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
What?
Part of: #67691
Migrating the sync package to Typescript.
Why?
Type safety.