Skip to content

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

@GerkinDev

Description

@GerkinDev

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions