expect-type
expect-type copied to clipboard
`expectTypeOf` does not work with `enum`s
expectTypeOf does not work with enums. It seems like types inference fails (playground).
This does not look to be related to #33. In our case this is a plain enum returned by a function:
import { expectTypeOf } from "expect-type";
enum Hand {
Left = "left",
Right = "right",
}
const left = Hand.Left;
// ^? const left: Hand.Left
const right = Hand.Right;
// ^? const right: Hand.Right
expectTypeOf(Hand.Left).toEqualTypeOf<Hand.Left>(); // fails, Expected: literal string: left, Actual: literal string: right
expectTypeOf(Hand.Right).toEqualTypeOf<Hand.Right>(); // fails, Expected: literal string: right, Actual: literal string: left
// the following work as expected
expectTypeOf<Hand.Left>().toEqualTypeOf<Hand.Left>();
expectTypeOf<Hand.Right>().toEqualTypeOf<Hand.Right>();
// can't use it, because function return type is tested
function getHand() {
return Hand.Left;
}
expectTypeOf(getHand()).toEqualTypeOf<Hand.Left>(); // fails, Expected: literal string: left, Actual: literal string: right