-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Interactivity API : Refactor interactivity-router to TS #61730
Conversation
const getPagePath = ( url ) => { | ||
const u = new URL( url, window.location ); | ||
const getPagePath = ( url: string ) => { | ||
const u = new URL( url, window.location.href ); |
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.
The URL()
constructor automatically converts window.location
to string using window.location.toString()
. However, TS is not happy about it so I explicitly pass href
.
// @ts-ignore | ||
if ( process.env.IS_GUTENBERG_PLUGIN ) { |
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.
I had to put a couple of @ts-ignore
directives so that TS is happy with process.env
.
Hopefully once #61486 is merged we can call globalThis.IS_GUTENBERG_PLUGIN
and remove the @ts-ignore
s.
Size Change: +578 B (+0.03%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
pages.set( pagePath, fetchPage( pagePath, options ) ); | ||
pages.set( | ||
pagePath, | ||
fetchPage( pagePath, { html: options.html } ) |
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.
fetchPage()
signature is:
const fetchPage = async ( url: string, { html }: { html: string } )
TS is not happy if we pass the whole options
object which contains additional properties.
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. |
* @param {Document} doc The document from which to fetch head assets. It should support standard DOM querying methods. | ||
* @param {Map} headElements A map of head elements to modify tracking the URLs of already processed assets to avoid duplicates. | ||
* @param {Document} doc The document from which to fetch head assets. It should support standard DOM querying methods. | ||
* @param {Map} headElements A map of head elements to modify tracking the URLs of already processed assets to avoid duplicates. |
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.
In Interactivity API package we are removing the type from the jsdoc to only leave it in TS.
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 do it in a follow-up PR, but, to keep consistency, it would be great to remove all types from the JS Docs.
) * Migrate interactivity-router to TS * Migrate head.js to TypeScript * chore: Update headElements type in fetchHeadAssets function * chore: Update getTagId function in head.ts * Removed jsdocs types --------- Co-authored-by: michalczaplinski <czapla@git.wordpress.org> Co-authored-by: cbravobernal <cbravobernal@git.wordpress.org>
What?
Closes #61371
Migrate the
@wordpress/interactivity-router
to TypeScript.Why?
To improve the developer experience.
Testing Instructions
This PR has no functional changes other than the TS types. All functionality should remain identical as before.