Closed olivierbeaulieu closed 2 years ago
Suggestions applied, thanks!
Hello, I think there should have been a test case to verify that assert.enumCase
really narrows the type, shouldn't it? The added test is runtime-only...
I thought about added this in - but I noticed that none of the other test suites did the same, so I left it out. Happy to add this in if the maintainers see the value.
Fixes https://github.com/sindresorhus/is/issues/148
Turns out typing this correctly was a bit trickier than I initially expected, since enums are both a value and a type.
Given this:
If
assert.enumCase
was typed to returnasserts value is T
(T being the inferred type ofDirection
), the asserted type ofinput
would becomestring & typeof Direction
, which is no good.Typing it as
asserts value is T[keyof T]
instead did the trick, makinginput
be typed asDirection
.