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

check goes by default into the promise overload #12

Closed
SimoneGianni opened this issue Aug 17, 2022 · 0 comments
Closed

check goes by default into the promise overload #12

SimoneGianni opened this issue Aug 17, 2022 · 0 comments

Comments

@SimoneGianni
Copy link
Owner

When writing something like the following:

function getSomething<T>() :T {...};

// ...

check(getSomething(), is.object.matching({...}));

Typescript will infer this signature:

(alias) check<unknown>(obj: Promise<unknown>, matcher: unknown): Promise<unknown> (+4 overloads)
import check

Because it will for some reason infer:

(alias) getSomething<Promise<never>>(): Promise<never>

This is a problem cause it triggers eslint rule about promises having to be awaited, and each check in the tests gets the warning even when it is not actually dealing with a promise but merely with an inferred type.

This could happen because of the order of the check overloads, having the promise based ones before the others.

Check:

  1. Why such ordering is necessary, eventually if inverted what would stop working properly (I suspect await check(async () => ..., is.throwing(...))
  2. If it's possible to use a negated promise type to force typescript to use another overload unless the method is really really returning a promise
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

No branches or pull requests

1 participant