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
Updated types for Lolex to the current version (3) #30309
Conversation
@zyishai Thank you for submitting this PR! 🔔 @Nemo157 @JoshuaKGoldberg @rogierschouten - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
As lolex core - this looks good. |
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.
Reviewing from just a TypeScript perspective since benjamingr approved the content changes - mostly great, with a few touchup requests.
types/lolex/index.d.ts
Outdated
@@ -215,6 +284,22 @@ export interface LolexInstallOpts { | |||
* | |||
* @param now Current time for the clock, as with lolex.createClock(). | |||
* @param toFake Names of methods that should be faked. | |||
* @type TClock Type of clock to create. | |||
* @type InstalledClock Type of clock to create. |
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.
Nit: if the generic is no longer here, you can just remove the type
line.
*/ | ||
export declare function install<TClock extends Clock>(opts?: LolexInstallOpts): TClock; |
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.
Instead of removing the <TClock extends Clock>
, could you change it to <TClock extends InstalledClock = InstalledClock>
? It used to be useful to specify which type of clock it was (browser vs node).
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.
Sure, will do. But could you explain to me what the = does? I didn't saw syntax like that in the documentation.
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.
These are Generic parameter defaults. If the user doesn't provide an explicitly value for the generic, it'll default to whatever that value is. The docs are a little out of date on these newer things 🙁 but it's super nifty!
Come to think of it, maybe the TClock
generic type should extend Clock
, and the return type be TClock & InstalledClock
? Something like (but with better names):
type InstalledClockBase = {
uninstall: () => void;
methods: FakeMethod[];
};
function install<TClock extends Clock>(opts?: LolexInstallOpts): TClock & InstalledClockBase;
type InstalledClock = InstalledClockBase & Clock;
const browserClock = install<BrowserClock>(); // BrowserClock & InstalledClock;
const clock = install(); // InstalledClock
|
||
browserClock.uninstall(); | ||
nodeClock.uninstall(); |
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.
Are the browser and node clocks no longer able to to uninstall();
?
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.
browser clocks are able to uninstall.
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.
@JoshuaKGoldberg in Lolex source, the method uninstall()
is only added to clocks that created with install()
, but clocks that were created with createClock()
have no uninstall()
. That's why I removed the uninstallation of browserClock
and nodeClock
and added installedClock
(line 31) and called uninstall()
on it (line 124).
@zyishai 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. Thank you! |
🔔 @JoshuaKGoldberg - Thanks for your review of this PR! Can you please look at the new code and update your review status if appropriate? |
This repository cannot be used directly as a source for the |
I figured out how to cobble it together by hand and will use that while we wait for this PR to be merged. // package.json
"@types/lolex": "https://github.com/thejohnfreeman/types-lolex.git#master" |
@thejohnfreeman this repository will release the new types automatically once this PR is merged. That'll happen automatically once >=1 person has signed off and nobody is requesting changes. ...but taking another glance, it looks like I dropped the ball and should have re-reviewed and approved! 😲 sorry for not coming back to this! /cc @zyishai |
A definition owner has approved this PR ⭐️. A maintainer will merge this PR shortly. If it shouldn't be merged yet, please leave a comment saying so and we'll wait. Thank you for your contribution to DefinitelyTyped! |
Please fill in this template.
npm test
.)npm run lint package-name
(ortsc
if notslint.json
is present).If changing an existing definition: