-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
TypeScript: Fix and improve types for private-apis #66667
TypeScript: Fix and improve types for private-apis #66667
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. |
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.
Thanks! We can clean up the pre-existing JSDoc types, just like in #66669.
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.
LGTM 🚀 Thanks @manzoorwanijk 🙌
*/ | ||
function unlock( object ) { | ||
function unlock( object: Record< symbol, WeakKey > ) { |
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.
A little better type would be unlock<T>(object: unknown): T
because:
- the function can safely work with any
object
and try to unlock it. We might run into problems with theRecord
type if the locked object doesn't have a compatible type. That will probably happen a lot as we migrate the poorly-typed-yet codebase. - we should be able to cast the return value to be an object of known type with private methods.
I predict that we'll run into these issues as we use the typed lock
/unlock
and will eventually come back to revisit this.
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.
Updated in #66682
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.
That signature seems to break a lot of existing poorly typed usage of lock
and unlock
* Convert private-apis package to TypeScript * Convert the usage of private-apis to TypeScript * Clean up JSDoc Co-authored-by: manzoorwanijk <[email protected]> Co-authored-by: tyxla <[email protected]>
What?
This PR converts
private-apis
package to TypeScript.Why?
Since private-apis package is used by many other packages, converting this package to TypeScript will pave the way for fixing types on other packages like
data
andcore-data
How?
The PR simply renamed the
.js
files to.ts
and adds the required types to the functions etc.Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast