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

[expect-type]: Allow negation of toBeCallableWith #6

Closed
GerkinDev opened this issue Mar 1, 2022 · 2 comments · Fixed by #16
Closed

[expect-type]: Allow negation of toBeCallableWith #6

GerkinDev opened this issue Mar 1, 2022 · 2 comments · Fixed by #16
Labels
documentation Improvements or additions to documentation

Comments

@GerkinDev
Copy link

I've noticed it's impossible to check for a function to not be callable with arguments

https://github.com/mmkal/ts/blob/main/packages/expect-type/src/index.ts#L111

In case of negated assertion, the check property is never.

So. I've tweaked around and I think the issue is that typing errors are generated during the last call, where type parameters are merged to generate a MISMATCH, spread as a rest parameter to generate type that can never be instantiated properly. But the current format of toBeCallableWith already takes a rest parameter for args.

So, here is the proposal: create a new method that takes arguments not as a rest tuple, but as a single tuple. Something like this:

export interface ExpectTypeOf<Actual, B extends boolean> {
    toBeCallableWithArgs: <T extends any[] | [never]>(args: T, ...MISMATCH: MismatchArgs<Extends<T, Params<Actual>>, B>) => true;
}

Thoughts ?

@mmkal mmkal transferred this issue from mmkal/ts Sep 25, 2022
@mmkal mmkal added will not fix This will not be worked on documentation Improvements or additions to documentation and removed will not fix This will not be worked on labels Oct 23, 2022
@mmkal
Copy link
Owner

mmkal commented Oct 23, 2022

Yes, this would be nice, but unfortunately breaks down for overloaded functions. I'll leave this open so it can be documented better, but basically - you'll have to use @ts-expect-error.

mmkal added a commit that referenced this issue Oct 1, 2023
@mmkal mmkal mentioned this issue Oct 1, 2023
2 tasks
@mmkal mmkal closed this as completed in #16 Oct 3, 2023
@mmkal mmkal closed this as completed in fd718dd Oct 3, 2023
@aryaemami59
Copy link
Collaborator

@mmkal I think I'm gonna give this a shot, it might be a good new feature for v1.

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

Successfully merging a pull request may close this issue.

3 participants