-
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
Convert autop package to TypeScript #61573
Convert autop package to TypeScript #61573
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. |
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @jpstevens! In case you missed it, we'd love to have you join us in our Slack community. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
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 is a nice improvement, thanks for working on the TS updates!
@@ -3,7 +3,7 @@ | |||
* | |||
* @type {RegExp} |
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.
You can remove all the JSDoc type anottations now, they are duplicate and redundant. The docgen
tool that generates the Markdown documentation will retrieve the types from the code, and should generate exactly the same output.
@@ -55,7 +55,7 @@ const htmlSplitRegex = ( () => { | |||
* | |||
* @return {string[]} The formatted text. |
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.
Same here, we only need to document the params, the types are on the function signature:
@param input The text which...
@return The formatted text.
@@ -65,7 +65,7 @@ function htmlSplit( input ) { | |||
// If the `g` flag is omitted, `index` is included. | |||
// `htmlSplitRegex` does not have the `g` flag so we can assert it will have an index number. | |||
// Assert `match.index` is a number. | |||
const index = /** @type {number} */ ( match.index ); | |||
const index = match.index!; |
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 don't use the !
operator, here match.index as number
is preferred.
@@ -480,7 +482,7 @@ export function removep( html ) { | |||
// Restore preserved tags. | |||
if ( preserve.length ) { | |||
html = html.replace( /<wp-preserve>/g, () => { | |||
return /** @type {string} */ ( preserve.shift() ); | |||
return preserve.shift()!; |
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.
Here also as string
is better.
👋 @jpstevens Thanks for this! If you'll update this PR on the latest |
What?
This PR converts the
autop
package to TypeScript.Why?
Ensures package is fully type checked.
How?
.ts
.ts
filesany
Testing Instructions
npm run test:unit -- packages/autop
tests passnpm run build:package-types
returns a zero exit code