Skip to content

[Bluebird] support then -> static .all -> then#46720

Closed
patricklx wants to merge 5 commits intoDefinitelyTyped:masterfrom
patricklx:patch-1
Closed

[Bluebird] support then -> static .all -> then#46720
patricklx wants to merge 5 commits intoDefinitelyTyped:masterfrom
patricklx:patch-1

Conversation

@patricklx
Copy link
Copy Markdown
Contributor

e.g. Promise.resolve([x1, x2]).all().then([x1, x2])

@patricklx patricklx changed the title [Bluebird] support then -> static .all [Bluebird] support then -> static .all -> then Aug 13, 2020
@typescript-bot typescript-bot added Critical package Untested Change This PR does not touch tests labels Aug 13, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

typescript-bot commented Aug 13, 2020

@patricklx 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.

Status

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

Once every item on this list is checked, I'll ask you for permission to merge and publish the changes.

Inactive

This PR has been inactive for 31 days — it is considered abandoned!


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 46720,
  "author": "patricklx",
  "owners": [
    "lhecker"
  ],
  "dangerLevel": "ScopedAndTested",
  "headCommitAbbrOid": "bc57437",
  "headCommitOid": "bc574372c5fd103179e12c3e1ccfcdcff5e37fb1",
  "mergeIsRequested": false,
  "stalenessInDays": 31,
  "lastPushDate": "2020-08-20T12:39:37.000Z",
  "lastCommentDate": "2020-08-21T09:40:46.000Z",
  "maintainerBlessed": false,
  "reviewLink": "https://github.com/DefinitelyTyped/DefinitelyTyped/pull/46720/files",
  "hasMergeConflict": false,
  "authorIsOwner": false,
  "isFirstContribution": false,
  "popularityLevel": "Popular",
  "newPackages": [],
  "packages": [
    "bluebird"
  ],
  "files": [
    {
      "path": "types/bluebird/bluebird-tests.ts",
      "kind": "test",
      "package": "bluebird"
    },
    {
      "path": "types/bluebird/index.d.ts",
      "kind": "definition",
      "package": "bluebird"
    }
  ],
  "hasDismissedReview": false,
  "ciResult": "fail",
  "ciUrl": "https://github.com/DefinitelyTyped/DefinitelyTyped/commit/bc574372c5fd103179e12c3e1ccfcdcff5e37fb1/checks?check_suite_id=1075551965",
  "reviewersWithStaleReviews": [
    {
      "reviewedAbbrOid": "e3f6ba0",
      "reviewer": "lhecker",
      "date": "2020-08-19T10:35:25Z"
    },
    {
      "reviewedAbbrOid": "f7d9f65",
      "reviewer": "lhecker",
      "date": "2020-08-17T11:58:16Z"
    },
    {
      "reviewedAbbrOid": "f4de064",
      "reviewer": "lhecker",
      "date": "2020-08-13T17:04:32Z"
    }
  ],
  "approvalFlags": 0,
  "isChangesRequested": false
}

@typescript-bot
Copy link
Copy Markdown
Contributor

🔔 @lhecker — 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.

@danger-public
Copy link
Copy Markdown

danger-public commented Aug 13, 2020

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.

bluebird (unpkg)

was missing the following properties:

  1. TypeError
  2. RangeError
  3. RejectionError
  4. fulfilled
  5. rejected
as well as these 1 other properties...

pending

Generated by 🚫 dangerJS against db02b80

@typescript-bot
Copy link
Copy Markdown
Contributor

👋 Hi there! I’ve run some quick measurements against master and your PR. These metrics should help the humans reviewing this PR gauge whether it might negatively affect compile times or editor responsiveness for users who install these typings.

Let’s review the numbers, shall we?

Comparison details 📊
master #46720 diff
Batch compilation
Memory usage (MiB) 48.2 54.6 +13.2%
Type count 7524 8832 +17%
Assignability cache size 805 868 +8%
Language service
Samples taken 2489 2489 0%
Identifiers in tests 2489 2489 0%
getCompletionsAtPosition
    Mean duration (ms) 105.6 106.0 +0.4%
    Mean CV 13.1% 12.6%
    Worst duration (ms) 228.1 220.0 -3.5%
    Worst identifier fooArr fooArr
getQuickInfoAtPosition
    Mean duration (ms) 100.2 101.0 +0.8%
    Mean CV 12.5% 12.2% -2.4%
    Worst duration (ms) 222.9 228.4 +2.5%
    Worst identifier resolve resolve

It looks like nothing changed too much. I won’t post performance data again unless it gets worse.

@typescript-bot typescript-bot added the Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. label Aug 13, 2020
Copy link
Copy Markdown
Contributor

@lhecker lhecker left a comment

Choose a reason for hiding this comment

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

Can you explain what this PR attempts to solve? Did you perhaps accidentally specify your tuple incorrectly?
Because the example you gave works just fine for me:

const x: [string, number] = ["hello", 10]; // correct tuple declaration (important!)
Bluebird.resolve(x).all().then(([x1, x2]) => {
    let y1: string = x1;
    let y2: number = x2;
});

("Requesting changes" so the bot knows what's up.)

@typescript-bot typescript-bot added the Revision needed This PR needs code changes before it can be merged. label Aug 13, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

@patricklx One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits or comments. If you disagree with the reviewer's comments, you can "dismiss" the review using GitHub's review UI. Thank you!

@lhecker
Copy link
Copy Markdown
Contributor

lhecker commented Aug 13, 2020

Ah nevermind I figured it out... You need two .then() calls. 😄

Copy link
Copy Markdown
Contributor

@lhecker lhecker left a comment

Choose a reason for hiding this comment

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

Finally I'd like to ask you to add a unit test about here.
I used the following code for testing (feel free to use it as well):

Bluebird.resolve(["", 0] as [string, number])
    .then(([x1, x2]) => [x1, x2])
    .then(([x1, x2]) => {
        const y1: string = x1;
        const y2: number = x2;
    });

Comment thread types/bluebird/index.d.ts Outdated
* The new promise will be rejected or resolved depending on the passed `fulfilledHandler`, `rejectedHandler` and the state of this promise.
*/
// Based on PromiseLike.then, but returns a Bluebird instance.
// to support static .all
Copy link
Copy Markdown
Contributor

@lhecker lhecker Aug 13, 2020

Choose a reason for hiding this comment

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

This comment is not very descriptive / not very helpful. You can remove it.

Comment thread types/bluebird/index.d.ts Outdated
then<T1, T2>(onFulfill?: (value: R) => Resolvable<[T1, T2]>, onReject?: (error: any) => Resolvable<[T1, T2]>): Bluebird<[T1, T2]>;
then<T1, T2, T3>(onFulfill?: (value: R) => Resolvable<[T1, T2, T3]>, onReject?: (error: any) => Resolvable<[T1, T2, T3]>): Bluebird<[T1, T2, T3]>;
then<T1, T2, T3, T4>(onFulfill?: (value: R) => Resolvable<[T1, T2, T3, T4]>, onReject?: (error: any) => Resolvable<[T1, T2, T3, T4]>): Bluebird<[T1, T2, T3, T4]>;
then<T1, T2, T3, T4, T5>(onFulfill?: (value: R) => Resolvable<[T1, T2, T3, T4, T5]>, onReject?: (error: any) => Resolvable<[T1, T2, T3, T4, T5]>): Bluebird<[T1, T2, T3, T4, T5]>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • Could you please order these overloads the same way as .all is overloaded? That is: Descending from the T1-T5 variant down to the T1-T2 one.
  • Additionally, to make it consistent, I'd like to ask you to please rename <U> to <T1> below.
  • The empty newline L66 can also be removed.

@typescript-bot typescript-bot removed Revision needed This PR needs code changes before it can be merged. Untested Change This PR does not touch tests labels Aug 14, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

@lhecker 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?

@typescript-bot typescript-bot added Popular package This PR affects a popular package (as counted by NPM download counts). and removed Critical package labels Aug 15, 2020
@patricklx
Copy link
Copy Markdown
Contributor Author

changed it so it correctly resolves promises

@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Aug 17, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

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

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

@lhecker
Copy link
Copy Markdown
Contributor

lhecker commented Aug 17, 2020

Oh I forgot about your PR… The changes look good to me now, but unfortunately you‘re exceeding the line length limit.
You can change it to look similar to the catch method. (Don’t forget the trailing comma though!)

@typescript-bot
Copy link
Copy Markdown
Contributor

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

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

Comment thread types/bluebird/index.d.ts Outdated
Resolvable<T1>,
Resolvable<T2>,
Resolvable<T3>
], onReject?: (error: any) => [Resolvable<T1>, Resolvable<T2>, Resolvable<T3>]): Bluebird<[T1, T2, T3]>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: You forgot to add line breaks here.
Since it's only a very minor stylistic issue I'll approve your PR regardless. Of course it'd be nice if you fixed it though. 😄

@typescript-bot
Copy link
Copy Markdown
Contributor

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

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

@lhecker
Copy link
Copy Markdown
Contributor

lhecker commented Aug 18, 2020

The changes look just perfect. 👌

But since yesterday I've spent some time thinking about the underlying reason why you're actually submitting this change...
Isn't the problem simply that you're declaring a tuple incorrectly?

Because if I change my sample code slightly to declare tuples consistently the typings work without any changes:

function makePair<T1, T2>(x: T1, y: T2): [T1, T2] {
    return [x, y];
}

Bluebird.resolve(makePair("", 0))
    .then(([x1, x2]) => makePair(x1, x2))
    .then(([x1, x2]) => {
        let y1: string = x1;
        let y2: number = x2;
    });

The above code will compile just fine with the current Bluebird typings, since we're always declaring tuples properly.
Wouldn't that fix your issue as well without adding those overloads?

@patricklx
Copy link
Copy Markdown
Contributor Author

patricklx commented Aug 18, 2020

Right, the test was not correct. But i now wonder if this changes are correct. Since it actually should not have passed. Since the array would contain the Promise in the last then. I guess i need to add something more to the static .all. something with resolvable.
I will have another look at this tomorrow.

@lhecker
Copy link
Copy Markdown
Contributor

lhecker commented Aug 19, 2020

FYI The test currently completes successfully even without any changes to the typings.

@patricklx
Copy link
Copy Markdown
Contributor Author

true, because of as [string, Promise<number>]. But is it really necessary to define the types everytime. It should be able to infer it from the types of each array item

});

Bluebird.resolve()
.then(() => ["", Bluebird.resolve(0)])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You're not declaring a tuple here (which was a point I made earlier).

e.g. `Promise.resolve([x1, x2]).all().then([x1, x2])`
@lhecker
Copy link
Copy Markdown
Contributor

lhecker commented Aug 19, 2020

Yeah I think I get your point, but I'm honestly not entirely sure if this PR presents a good idea anymore...
Because this inference problem you mention is present in every other Bluebird method as well. Should we now start overloading every method? I believe that would be overkill.
Furthermore the native Promise and PromiseLike types are something of a prototype for Bluebird and they don't define any such overloads either. 🤔

@lhecker
Copy link
Copy Markdown
Contributor

lhecker commented Aug 19, 2020

To make a specific example for my previous comment: After we merged this PR, the static resolve method will continue to not infer tuple types, which is inconsistent in respect to the new then method definition. Should resolve also have such overloads? And reduce? And all the others? Now that I had a few days to think about this PR I'm not sure if it presents a direction we should pursue with these typings. What's your opinion?

@patricklx
Copy link
Copy Markdown
Contributor Author

like this then?
quite new though: microsoft/TypeScript#39094

@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Aug 20, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

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

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

@typescript-bot
Copy link
Copy Markdown
Contributor

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

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

@typescript-bot
Copy link
Copy Markdown
Contributor

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

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

@typescript-bot typescript-bot added The CI failed When GH Actions fails and removed The CI failed When GH Actions fails labels Aug 20, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

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

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

@typescript-bot
Copy link
Copy Markdown
Contributor

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

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

@lhecker
Copy link
Copy Markdown
Contributor

lhecker commented Aug 21, 2020

Using variadic tuple types we could simplify a lot of the redundant declarations.
I really don't mean to be rude, but as a maintainer of these typings I objectively believe, that we shouldn't deviate too far from the Promise and PromiseLike definitions within TS' stdlib.
In order for your PR to be consistent you'd have to add variadic overloads to pretty much every single method.
At the time of writing only the three all methods (including Bluebird's addition of allSettled) have overloads for tuple types, which reflects the stdlib definition of Promise.all which is similarly the only method with overloads to infer tuples.
For consistency and a reduction of "surprise" during coding I'd prefer keeping it that way and sticking with the stdlib.

@typescript-bot
Copy link
Copy Markdown
Contributor

@patricklx I haven't seen any activity on this PR in more than 3 weeks, and this PR currently has problems that prevent it from being merged. The PR will be closed in a week if the issues aren't addressed.

@typescript-bot typescript-bot added the Abandoned This PR had no activity for a long time, and is considered abandoned label Sep 22, 2020
@typescript-bot
Copy link
Copy Markdown
Contributor

@patricklx To keep things tidy, we have to close PRs that aren't mergeable and don't have activity in the last month. No worries, though — please open a new PR if you'd like to continue with this change. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Abandoned This PR had no activity for a long time, and is considered abandoned Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. Popular package This PR affects a popular package (as counted by NPM download counts). The CI failed When GH Actions fails

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants