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

[ember] @ember/object Correct arguments for Evented #45978

Merged
merged 1 commit into from Jul 9, 2020

Conversation

wagenet
Copy link
Contributor

@wagenet wagenet commented Jul 9, 2020

Please fill in this template.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Add or edit tests to reflect the change. (Run with npm test.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run npm run lint package-name (or tsc if no tslint.json is present).
    NOTE: Lint is failing due to issues unrelated to my change.

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes:

@typescript-bot typescript-bot added the Popular package This PR affects a popular package (as counted by NPM download counts). label Jul 9, 2020
@typescript-bot
Copy link
Contributor

typescript-bot commented Jul 9, 2020

@wagenet Thank you for submitting this PR! I see this is your first time submitting to DefinitelyTyped 👋 — I'm the local bot who will help you through the process of getting things through.

This is a live comment which I will keep updated.

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

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": 45978,
  "author": "wagenet",
  "owners": [
    "mike-north",
    "chriskrycho",
    "dfreeman",
    "jamescdavis"
  ],
  "dangerLevel": "ScopedAndTested",
  "headCommitAbbrOid": "392cee0",
  "headCommitOid": "392cee084fca237adf71ef10b0481c8cd53257fe",
  "mergeIsRequested": true,
  "stalenessInDays": 0,
  "lastCommitDate": "2020-07-09T17:42:37.000Z",
  "lastCommentDate": "2020-07-09T19:23:43.000Z",
  "maintainerBlessed": false,
  "reviewLink": "https://github.com/DefinitelyTyped/DefinitelyTyped/pull/45978/files",
  "hasMergeConflict": false,
  "authorIsOwner": false,
  "isFirstContribution": true,
  "popularityLevel": "Popular",
  "anyPackageIsNew": false,
  "packages": [
    "ember__object"
  ],
  "files": [
    {
      "filePath": "types/ember__object/evented.d.ts",
      "kind": "definition",
      "package": "ember__object"
    },
    {
      "filePath": "types/ember__object/test/event.ts",
      "kind": "test",
      "package": "ember__object"
    }
  ],
  "hasDismissedReview": false,
  "ciResult": "pass",
  "lastReviewDate": "2020-07-09T17:57:16.000Z",
  "reviewersWithStaleReviews": [],
  "approvalFlags": 2,
  "isChangesRequested": false
}

@typescript-bot typescript-bot added this to Waiting for Code Reviews in New Pull Request Status Board Jul 9, 2020
@typescript-bot
Copy link
Contributor

🔔 @mike-north @chriskrycho @dfreeman @jamescdavis - 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.

Comment on lines 13 to 15
method: ((this: Target, ...args: any[]) => void) | string
): this;
on(name: string, method: (...args: any[]) => void): this;
on(name: string, method: ((...args: any[]) => void) | string): this;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suuuuper nit: for readability, can we flip the order of these? I always have a devil of a time parsing parenthesized function expressions like this. So method: string | (this: Target, ...args: any[]) => void, etc.

@@ -51,6 +51,5 @@ export default Evented;
* a specified event or events are triggered.
*/
export function on(
eventNames: string,
func: (...args: any[]) => void
...args: Array<string | ((...args: any[]) => 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 believe this type is wrong, because it's not actually possible for these to be mixed. The type as written here would let you write this:

on(
  'click',
  (someEv) => {
    console.log(someEv);
  },
  'dblclick',
  'mouseover'
);

In order to make it take a spread of arguments followed by the callback, we should support it now via overloads, and then once we bump our minimum supported TS version to 4.0 (presumably in the first half 2021) I think we'll be able to use TS 4.0's support for variadic tuples to make this work as desired.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I agree that this definition is too accepting. I just chose it because it was what's in the source and the existing definition disallows valid options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chriskrycho what do you have in mind for overloads? Just a number of variants with increasing numbers of eventName arguments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I'm not seeing how variadic tuples would help us here, but it's also very possible that I'm missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, looks like this would work in TS 4:

type EventNames = string[];
type OnArgs = [...EventNames, (...args: any[]) => void];
export function on(...args: OnArgs): (...args: any[]) => void;

Copy link
Contributor

Choose a reason for hiding this comment

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

Exactly that for TS 4. For TS <4, yeah, you’d do a bunch of increasing event names—we tend to go up to 5 or 6 most similar places in the Ember types.

@typescript-bot typescript-bot added the Revision needed This PR needs code changes before it can be merged. label Jul 9, 2020
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Author Action in New Pull Request Status Board Jul 9, 2020
@typescript-bot
Copy link
Contributor

@wagenet 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!

@typescript-bot typescript-bot removed the Revision needed This PR needs code changes before it can be merged. label Jul 9, 2020
@typescript-bot typescript-bot moved this from Needs Author Action to Waiting for Code Reviews in New Pull Request Status Board Jul 9, 2020
@wagenet wagenet force-pushed the ember-evented-fixes branch 2 times, most recently from 398e53e to 50d7a6d Compare July 9, 2020 16:52
@typescript-bot
Copy link
Contributor

@chriskrycho 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
Contributor

@chriskrycho chriskrycho left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes—one tiny further tweak, and we’ll be good!

Comment on lines 54 to 59
* The actual implementation allows for any number of eventName strings followed by
* the function to be called. In TypeScript 4.0 this could be better described with:
*
* type EventNames = string[];
* type OnArgs = [...EventNames, (...args: any[]) => void];
* export function on(...args: OnArgs): (...args: any[]) => void;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let’s move these to a //-style comment above this, instead of in the docstring: the docstring will show up for everyone who uses the type definition… which includes all JS users who are using VS Code, since it does automatic type acquisition in the background to power completions for the language server. 😱

@typescript-bot typescript-bot added the Revision needed This PR needs code changes before it can be merged. label Jul 9, 2020
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Author Action in New Pull Request Status Board Jul 9, 2020
@typescript-bot
Copy link
Contributor

@wagenet 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!

@typescript-bot typescript-bot removed the Revision needed This PR needs code changes before it can be merged. label Jul 9, 2020
@typescript-bot typescript-bot moved this from Needs Author Action to Waiting for Code Reviews in New Pull Request Status Board Jul 9, 2020
Copy link
Contributor

@chriskrycho chriskrycho left a comment

Choose a reason for hiding this comment

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

Thanks so much for the quick iteration! Looks good! :shipit:

@typescript-bot typescript-bot added Owner Approved A listed owner of this package signed off on the pull request. Self Merge This PR can now be self-merged by the PR author or an owner labels Jul 9, 2020
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Waiting for Author to Merge in New Pull Request Status Board Jul 9, 2020
@wagenet
Copy link
Contributor Author

wagenet commented Jul 9, 2020

@chriskrycho thanks for your quick reviews!

@wagenet
Copy link
Contributor Author

wagenet commented Jul 9, 2020

@chriskrycho any clue what's up with CI?

@chriskrycho
Copy link
Contributor

Note sure why the benchmark is taking so long, but if you follow the good bot’s instructions and post “Ready to merge” in a comment I think it’ll get pushed through automatically as soon as that benchmark finishes! 😅

@wagenet
Copy link
Contributor Author

wagenet commented Jul 9, 2020

@chriskrycho looks like the benchmark is stuck in a restart loop. Not sure who to escalate that to.

@wagenet
Copy link
Contributor Author

wagenet commented Jul 9, 2020

Ready to merge

@typescript-bot typescript-bot moved this from Waiting for Author to Merge to Recently Merged in New Pull Request Status Board Jul 9, 2020
@typescript-bot typescript-bot merged commit 68523d9 into DefinitelyTyped:master Jul 9, 2020
@wagenet
Copy link
Contributor Author

wagenet commented Jul 9, 2020

Guess we didn't need that benchmark to finish!

@wagenet wagenet deleted the ember-evented-fixes branch July 9, 2020 19:24
@typescript-bot
Copy link
Contributor

I just published @types/ember__object@3.12.1 to npm.

@chriskrycho
Copy link
Contributor

Whew!

@typescript-bot
Copy link
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?

Before we get into it, I need to mention that the language service crashed while taking these measurements. This isn’t your fault—on the contrary, you helped us find a probably TypeScript bug! But, be aware that these results may or may not be quite what they should be, depending on how many locations in your tests caused a crash. Paging @andrewbranch to investigate.

Comparison details 📊
master #45978 diff
Batch compilation
Memory usage (MiB) 76.3 78.4 +2.8%
Type count 14971 15016 0%
Assignability cache size 4385 4385 0%
Language service
Samples taken 1348 1380 +2%
Identifiers in tests 1665 1697 +2%
getCompletionsAtPosition
    Mean duration (ms) 420.9 418.8 -0.5%
    Mean CV 10.6% 10.7%
    Worst duration (ms) 803.2 804.3 +0.1%
    Worst identifier sort notEmpty
getQuickInfoAtPosition
    Mean duration (ms) 404.8 404.4 -0.1%
    Mean CV 10.5% 10.8% +2.5%
    Worst duration (ms) 646.8 598.1 -7.5%
    Worst identifier a reads

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 Jul 9, 2020
ngbrown pushed a commit to ngbrown-forks/DefinitelyTyped that referenced this pull request Jul 11, 2020
@typescript-bot typescript-bot removed this from Recently Merged in New Pull Request Status Board Jul 13, 2020
danielrearden pushed a commit to danielrearden/DefinitelyTyped that referenced this pull request Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Owner Approved A listed owner of this package signed off on the pull request. 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). 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.

None yet

3 participants