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

Make defaultResolver type more flexible #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

IanVS
Copy link

@IanVS IanVS commented Sep 10, 2021

There is work ongoing in jest to allow async resolvers, and since jest-pnp-resolver is built-in, we'll need a small tweak to the typescript types. This PR just makes the types a bit more flexible, to allow an async defaultResolver while continuing to also support sync as well.

The trick here is using the ReturnType of the default resolver as the return type of the pnp resolver.

@arcanis
Copy link
Owner

arcanis commented Sep 10, 2021

Sounds good to me! Should I bump it as a major, or is minor fine?

@IanVS
Copy link
Author

IanVS commented Sep 10, 2021

There should be no change to current behavior, since it's just making the types a bit more correct as to the existing behavior (while opening the way for future changes to jest). A patch would probably be fine, but it can be minor if you'd like as well.

@IanVS
Copy link
Author

IanVS commented Oct 4, 2021

Hi @arcanis, do you have any thoughts on this change? Thanks!

@IanVS
Copy link
Author

IanVS commented Nov 5, 2021

Hi, just another friendly ping on this small PR that it sounded like you were on board with.

@IanVS
Copy link
Author

IanVS commented Dec 2, 2021

👋 there! Any chance you could merge this?

@IanVS
Copy link
Author

IanVS commented Sep 12, 2023

I'm cleaning up my open PRs that don't seem to have a chance of merging.

@IanVS IanVS closed this Sep 12, 2023
@arcanis
Copy link
Owner

arcanis commented Sep 12, 2023

Hey @IanVS, apologies, I completely missed your pings - I'll look at applying and publishing your patch later today (I assume you still need it?)

@IanVS
Copy link
Author

IanVS commented Sep 12, 2023

I actually don't know if it's still needed. I haven't been very involved in jest development since this. According to my comment jestjs/jest#11540 (comment), it sounds like this is a good change to make regardless. But @SimenB would be more knowledgable about it at this point I think.

@SimenB
Copy link

SimenB commented Sep 12, 2023

Hah wow, old one 😅 is there anything to do here?

@SimenB
Copy link

SimenB commented Sep 12, 2023

Async resolver landed some time ago, fwiw

@IanVS
Copy link
Author

IanVS commented Sep 12, 2023

Async resolver landed some time ago, fwiw

Yep, I remember you worked quite closely with me on that, thanks.

I think this change is only needed if you wanted to re-add a default async resolver, which was removed here: jestjs/jest@8c21ab5 (#11540)

Currently, it seems that jest-pnp-resolver is only used in the default (sync) resolver.

@SimenB
Copy link

SimenB commented Sep 12, 2023

Right, but does that matter? Async can call into sync without issue. Is there any feature (type or otherwise) that needs this?

(Thanks again for the patience in that PR 😀)

@IanVS
Copy link
Author

IanVS commented Sep 12, 2023

I think so, yes, because of the difference in the shape of defaultResolver.options (async vs sync) which is provided as the second argument. There will be a type error without this PR, which I had to use an ignore comment to work around previously:

jestjs/jest@8c21ab5 (#11540)

It's all starting to come back to me now…

So yeah, I think this is still a good change to make. I'll reopen.

Thanks again for the patience in that PR

Haha, likewise!

@IanVS IanVS reopened this Sep 12, 2023
request: string,
options: JestResolverOptions,
): string;
export default function resolve<D extends (request: string, options: JestResolverOptions<D>) => any>(
Copy link

Choose a reason for hiding this comment

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

Is any a good default? Should it be a string?

Copy link
Author

Choose a reason for hiding this comment

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

That was the original rub, that the defaultResolverAsync returned a promise and not a string. Here's a playground I threw together, and I'm not sure how to specify anything other than any here. (I tried unknown and string | Promise<string>)

https://tsplay.dev/N7V04w

Copy link

Choose a reason for hiding this comment

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

A resolver should always return a string or null (from memory, I can very tomorrow)

Copy link
Author

Choose a reason for hiding this comment

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

Even an async resolver? Wouldn't it return a promise?

Copy link
Author

Choose a reason for hiding this comment

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

Seems like that would work, yeah. Here's a version that's a bit more strict and expects string or null (or promise of one) to be returned from the resolver https://tsplay.dev/mA2Z8W

Though in the end, I wonder if this should really care what the resolver returns. So maybe your version is better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants