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.
When I use
expectTypeOf, I expect it to fail when I passanyas input. For example,toBeString()should strictly only allow strings and not any other type...includingany.This is particular useful in cases when your types reason about
any, I need to strictly know that a type will fail if itsanyor not. For example:If I use
CustomTypesomewhere, I'd like to testexpectTypeOf(value).toBeNumber();and have it fail if it'sanywhen I don't expect it to be.This issue was originally opened at vitest-dev/vitest#4205.