You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
This will be fixed by #16. And looks to be a duplicate of #32. If you're using expect-type directly, you can try the next dist tag now. The version in vitest will be bumped by vitest-dev/vitest#4206. Simplest thing to do will just be to wait for that.
constgoodIntParser=(s: string)=>Number.parseInt(s,10)constbadIntParser=(s: string)=>JSON.parse(s)// uh-oh - works at runtime if the input is a number, but return 'any'expectTypeOf(goodIntParser).returns.toBeNumber()// @ts-expect-error - if you write a test like this, `.toBeNumber()` will let you know your implementation returns `any`.expectTypeOf(badIntParser).returns.toBeNumber()
When I use
expectTypeOf
, I expect it to fail when I passany
as 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 itsany
or not. For example:If I use
CustomType
somewhere, I'd like to testexpectTypeOf(value).toBeNumber();
and have it fail if it'sany
when I don't expect it to be.This issue was originally opened at vitest-dev/vitest#4205.
The text was updated successfully, but these errors were encountered: