I want to get all available keys of an union type.
interface Foo {
foo: string;
}
interface Bar {
bar: string;
}
type Batz = Foo | Bar;
type AvailableKeys = keyof Batz;
I want to have 'foo' | 'bar'
as result of AvailableKeys
but it is never
(as alternative I could do keyof (Foo & Bar)
, what produces exact the required type but I want to avoid to repeat the Types).
I found already the issue keyof
union type should produce union of keys at github. I understand the answer, that keyof UnionType
should not produce all possible keys.
So my question is: Is there an other way to get the list of all possible keys (it is ok if the verison 2.8 of tsc is required)?