Consider the below code.
type UnionType = 'foo' | 'bar' | 'baz'
const obj = {
foo: 'huh',
bar: 'hmm'
}
function func(input: UnionType) {
if(input in obj) {
input
}
}
Playground link.
input
is not being narrowed to 'foo' | 'bar'
. Why is that?
Is there a way to make it narrow the union down, without explicitly re-stating the object keys?