Skip to content

expectTypeOf allows an incorrect any value instead of the specified type #38

@kwangure

Description

@kwangure

When I use expectTypeOf, I expect it to fail when I pass any as input. For example, toBeString() should strictly only allow strings and not any other type...including any.

expectTypeOf(1).toBeString(); //  Fails 👍
expectTypeOf(1 as any).toBeString(); // Passes 👎

This is particular useful in cases when your types reason about any, I need to strictly know that a type will fail if its any or not. For example:

type IsAny<T> = 0 extends 1 & T ? true : false;

export type CustomType<T> = IsAny<T> extends true ? number: any;

If I use CustomType somewhere, I'd like to test expectTypeOf(value).toBeNumber(); and have it fail if it's any when I don't expect it to be.

This issue was originally opened at vitest-dev/vitest#4205.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions