Skip to content
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 warning package to TypeScript #61522

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

jpstevens
Copy link
Contributor

@jpstevens jpstevens commented May 9, 2024

What?

This PR converts the warning package to TypeScript.

Why?

Ensures package is fully type checked.

How?

  • converted files to .ts
  • added explicit return types for functions in index and utils files

Testing Instructions

npm run test:unit -- packages/warning tests pass
npm run build:package-types returns a zero exit code

Copy link

github-actions bot commented May 9, 2024

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: jpstevens <jpstevens@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label May 9, 2024
Copy link

github-actions bot commented May 9, 2024

👋 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.

@Mamaduka Mamaduka added [Type] Enhancement A suggestion for improvement. [Package] Warning /packages/warning and removed First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository labels May 14, 2024
@youknowriad
Copy link
Contributor

youknowriad commented May 14, 2024

Thanks for your help typing all these packages.

I thought this package was already fully typed. Is renaming to ts files necessary?

@sirreal Can you help me navigate this a bit :P

@sirreal
Copy link
Member

sirreal commented May 14, 2024

I thought this package was already fully typed. Is renaming to ts files necessary?

Changing the file extension doesn't change much here. This package is typechecked, types are generated for the package, and no complex types are necessary that can't be easily expressed in JSDoc.

The type of the public API of the current version this package can be found here:
https://unpkg.com/browse/@wordpress/warning@2.57.0/build-types/index.d.ts

That would be exactly the same.

The explicit return type annotations added to the two functions might be a nice change, they're both inferred to be the same thing, but some would argue that adding those annotations is a good thing.

@@ -24,7 +24,7 @@ function isDev() {
* }
* ```
*/
export default function warning( message ) {
export default function warning( message: string ): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing that we need to remove the types from the JSDocs to be consistent with how we document ts files.

Copy link
Member

Choose a reason for hiding this comment

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

Yes. If we change the files to TypeScript we should definitely remove the types from JSDoc 💯

@@ -4,4 +4,4 @@
*
* @type {Set<string>}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably remove this as well right?

@youknowriad
Copy link
Contributor

I've been thinking about this PR. While I see some value in it, I'm not sure that we should move forward with it. It has no real impact on the generated types or whether the package is fully typed. It's really a code style change.

And the thing is that while for this package it's fine, it may create a snowball effect for other packages and we'll find our selves spending time rewriting JS to TS for a lot of code and reviewing a lot of code for a small benefit.

@jsnajdr
Copy link
Member

jsnajdr commented May 15, 2024

My main argument in favor of TS conversions like this is that the JSDoc type annotations are a rather obscure feature and most people are not familiar with them. I guess that many would be surprised to learn that such a thing even exists.

Who is really fluent in knowing that @template {string} T means <T extends string> or what's the difference between @prop {string?} and @prop {string=}? I believe the native syntax is more readable for virtually everyone, and is much better searchable in docs, Stack Overflow questions etc.

@youknowriad
Copy link
Contributor

I don't feel that strongly, so I can be convinced, happy to hear other opinions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Warning /packages/warning [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants