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

chore(jest-jasmine2): remove usage of Function type #10216

Merged
merged 2 commits into from Jul 5, 2020
Merged

chore(jest-jasmine2): remove usage of Function type #10216

merged 2 commits into from Jul 5, 2020

Conversation

G-Rath
Copy link
Contributor

@G-Rath G-Rath commented Jun 28, 2020

Summary

Improves the types for jest-jasmine2 to remove banned types (specifically Function & object) as part of #10177.

The only two files that have banned types (well, type: Function) are:

  • errorOnPrivate: I suspect that Function might actually be the "right" type to use here, but more importantly it's usage is for a passthrough parameter to ErrorWithStack which comes from jest-utils, so the correct type will be whatever replaces the Function usage in that package.

  • jasmineAsyncInstall: I've almost got this typed, but the remaining errors point towards a type being incorrect somewhere that I can't pin down. I think there's a bit of critical understanding that would make it all click that I'm missing.

    I've included the work in this commit, so CI will fail, but am happy to revert that section to get the rest of the changes landed.

Test plan

See if the tests pass :D

env: Jasmine['currentEnv_'],
) {
return function <T>(
fn: Function | (() => Promise<T>) | GeneratorFunction | undefined,
fn:
| ((done: DoneFn) => void | PromiseLike<T>)
Copy link
Member

Choose a reason for hiding this comment

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

It should be an error to both take a done function and return a promise

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will cause some major type problems, as everywhere else is expecting only (done: DoneFn) => void.

For the record, by unioning the functions TS can't support both of them when doing .call, so it favors (done: Done) => void, meaning that returnValue.then is invalid as it has type void.

This can be resolved by using an interface:

interface OneOrTheOther {
  (done: DoneFn): void;
  (): PromiseLike<void>;
}

This then takes us back to where we were before, but this time it's the opposite: TS is complaining asyncJestTest doesn't fit because it's of type (done: DoneFn) => void instead of OneOrTheOther 😬

Copy link
Member

Choose a reason for hiding this comment

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

😞

@SimenB SimenB merged commit c2d4aa5 into jestjs:master Jul 5, 2020
@SimenB
Copy link
Member

SimenB commented Jul 5, 2020

Thanks!

@G-Rath G-Rath deleted the improve-jest-jasmine2-types branch July 5, 2020 20:14
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants