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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
type JestResolverOptions = {
type JestResolverOptions<T> = {
basedir: string;
defaultResolver: (request: string, opts: any) => string,
defaultResolver: T;
extensions?: Array<string>,
};

export default function resolve(
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.

request: string,
options: JestResolverOptions<D>
): ReturnType<D>