I'm trying to filter out enum values and I have some issues with typings/filtering these entries. I cannot type my filter function correctly. I spent some hours and I have no idea how to do it.
What I want to achieve:
I have enum like:
enum AllEntries {
A = 'a',
B = 'b',
C = 'c',
D = 'd'
}
And I want to have this enum to have some entries filtered out for some keys in array:
const testObject = {
// this one should have possibility to access all enum keys except A
withoutA: filterEnum(AllEntries, [AllEntries.A]),
// this one should have possibility to access all enum keys except A
all: AllEntries,
// this one should have possibility to access only D entry
onlyD: filterEnum(AllEntries, [AllEntries.A, AllEntries.B, AllEntries.D])
}
I want function filterEnum to return "clone" of AllEntries without values given in second parameter, also it shouldn't allow me to access eg. A key in testObject.withoutA
I'm trying to use Exclude utility type etc, but with no results. Do you have any ideas?
Example code that shows what I want to achieve (with nasty any):