Skip to content

[@wordpress/data] Fix return value of dispatched actions to be a Promise#60693

Merged
typescript-bot merged 10 commits intoDefinitelyTyped:masterfrom
sirbrillig:fix-return-value-of-wordpress-data-dispatched-actions
Jun 20, 2022
Merged

[@wordpress/data] Fix return value of dispatched actions to be a Promise#60693
typescript-bot merged 10 commits intoDefinitelyTyped:masterfrom
sirbrillig:fix-return-value-of-wordpress-data-dispatched-actions

Conversation

@sirbrillig
Copy link
Copy Markdown
Contributor

@sirbrillig sirbrillig commented Jun 6, 2022

Please fill in this template.

If changing an existing definition:

@sirbrillig sirbrillig changed the title [@wordpress/data] Fix return value of dispatched actions [@wordpress/data] Fix return value of dispatched actions to be a Promise Jun 6, 2022
@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Jun 6, 2022

@sirbrillig Thank you for submitting this PR!

This is a live comment which I will keep updated.

1 package in this PR

Code Reviews

Because you edited one package and updated the tests (👏), I can help you merge this PR once someone else signs off on it.

You can test the changes of this PR in the Playground.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ✅ Most recent commit is approved by type definition owners, DT maintainers or others

All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 60693,
  "author": "sirbrillig",
  "headCommitOid": "66189e99b4fbbaf7f28f07b5e533451b695c8e31",
  "mergeBaseOid": "595c471bd4aefa44a5d0ee49c4d73f373c319d18",
  "lastPushDate": "2022-06-08T22:28:20.000Z",
  "lastActivityDate": "2022-06-20T19:32:54.000Z",
  "mergeOfferDate": "2022-06-16T16:24:22.000Z",
  "mergeRequestDate": "2022-06-20T19:32:54.000Z",
  "mergeRequestUser": "sirbrillig",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Well-liked by everyone",
  "pkgInfo": [
    {
      "name": "wordpress__data",
      "kind": "edit",
      "files": [
        {
          "path": "types/wordpress__data/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/wordpress__data/wordpress__data-tests.tsx",
          "kind": "test"
        }
      ],
      "owners": [
        "dsifford",
        "sirreal"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "dmsnell",
      "date": "2022-06-16T16:23:34.000Z",
      "isMaintainer": false
    },
    {
      "type": "stale",
      "reviewer": "sarayourfriend",
      "date": "2022-06-07T21:03:08.000Z",
      "abbrOid": "6353f1f"
    },
    {
      "type": "stale",
      "reviewer": "sirreal",
      "date": "2022-06-06T19:34:21.000Z",
      "abbrOid": "e4798c4"
    }
  ],
  "mainBotCommentID": 1147822909,
  "ciResult": "pass"
}

@typescript-bot
Copy link
Copy Markdown
Contributor

🔔 @dsifford @sirreal — please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

@typescript-bot typescript-bot added The CI failed When GH Actions fails Owner Approved A listed owner of this package signed off on the pull request. labels Jun 6, 2022
@typescript-bot
Copy link
Copy Markdown
Contributor

@sirbrillig The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review.

@typescript-bot typescript-bot removed Owner Approved A listed owner of this package signed off on the pull request. The CI failed When GH Actions fails labels Jun 6, 2022
@DangerBotOSS
Copy link
Copy Markdown

DangerBotOSS commented Jun 6, 2022

Inspecting the JavaScript source for this package found some properties that are not in the .d.ts files.
The check for missing properties isn't always right, so take this list as advice, not a requirement.

wordpress__data (unpkg)

was missing the following properties:

  1. AsyncModeProvider
  2. controls
  3. AsyncModeProvider
  4. controls

Generated by 🚫 dangerJS against 66189e9

@typescript-bot
Copy link
Copy Markdown
Contributor

@sirreal Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@sirbrillig
Copy link
Copy Markdown
Contributor Author

Pinging also @dmsnell and @jsnajdr because you have much more TS experience with this package than I do.

@sirbrillig
Copy link
Copy Markdown
Contributor Author

Updated to make this less breaking thanks to an excellent idea by @sarayourfriend.

@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Jun 6, 2022
@typescript-bot
Copy link
Copy Markdown
Contributor

@sirbrillig The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review.

@typescript-bot typescript-bot added The CI failed When GH Actions fails and removed The CI failed When GH Actions fails labels Jun 6, 2022
@typescript-bot
Copy link
Copy Markdown
Contributor

@sirbrillig The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review.

@typescript-bot typescript-bot removed the The CI failed When GH Actions fails label Jun 6, 2022
Co-authored-by: sarayourfriend <24264157+sarayourfriend@users.noreply.github.com>
@typescript-bot typescript-bot added the Where is GH Actions? GH Actions didn't give a response to this PR label Jun 7, 2022
@typescript-bot typescript-bot added The CI failed When GH Actions fails and removed Where is GH Actions? GH Actions didn't give a response to this PR labels Jun 7, 2022
@typescript-bot
Copy link
Copy Markdown
Contributor

@sirbrillig The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review.

@typescript-bot typescript-bot removed the The CI failed When GH Actions fails label Jun 7, 2022
@typescript-bot
Copy link
Copy Markdown
Contributor

@sarayourfriend, @sirreal Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

Copy link
Copy Markdown
Contributor

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

We'll want to add a test that passes false for DoEnsurePromise as well.

@dmsnell
Copy link
Copy Markdown
Contributor

dmsnell commented Jun 8, 2022

Would this be simpler if we relaxed the type parameters?

Record<string, <T extends Promise<any> | any>(...args: readonly any[]) => T>

this captures the Promise nature without any further work on our part. I think even <T> is fine without the extends other than it communicates to devs that Promise<> is likely

@sirbrillig
Copy link
Copy Markdown
Contributor Author

sirbrillig commented Jun 8, 2022

Would this be simpler if we relaxed the type parameters?

Making it simpler sounds nice, but when I try using that type in actual code, the type of an action without an explicit generic becomes const doSomething: <unknown>(...args: readonly any[]) => unknown and if I try to add .then() I get a type error because unknown has no properties.

For reference, here's the code I'm using to test these changes. Currently it has an explicit generic, but IMO it should work without a generic at all because the default behavior is to return a Promise.

Copy link
Copy Markdown
Contributor

@dmsnell dmsnell left a comment

Choose a reason for hiding this comment

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

Let's fly with this. Seems sufficient enough; thanks for addressing the promise issue.

@typescript-bot typescript-bot added Other Approved This PR was reviewed and signed-off by a community member. Self Merge This PR can now be self-merged by the PR author or an owner labels Jun 16, 2022
@typescript-bot
Copy link
Copy Markdown
Contributor

@sirbrillig: Everything looks good here. I am ready to merge this PR (at 66189e9) on your behalf whenever you think it's ready.

If you'd like that to happen, please post a comment saying:

Ready to merge

and I'll merge this PR almost instantly. Thanks for helping out! ❤️

(@dsifford, @sirreal: you can do this too.)

@sirbrillig
Copy link
Copy Markdown
Contributor Author

Ready to merge

@typescript-bot typescript-bot merged commit d8446c6 into DefinitelyTyped:master Jun 20, 2022
@sirbrillig sirbrillig deleted the fix-return-value-of-wordpress-data-dispatched-actions branch June 20, 2022 19:36
sirbrillig added a commit to Automattic/wp-calypso that referenced this pull request Jan 31, 2023
sirbrillig added a commit to Automattic/wp-calypso that referenced this pull request Feb 1, 2023
…ad of void (#72841)

* Change DispatchFromMap to return Promise<void> instead of void

See https://github.com/WordPress/gutenberg/blob/6aef6e6b9b5cf2f5aeff6145cd24181edf0d43f0/packages/data/README.md#user-content-dispatch

"Note: Action creators returned by the dispatch will return a promise when they are called."

This was previously fixed in the DT types here: DefinitelyTyped/DefinitelyTyped#60693

* Void dispatched Promise to useEffect cleanup in CreateSiteError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Other Approved This PR was reviewed and signed-off by a community member. Self Merge This PR can now be self-merged by the PR author or an owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants