I am using a library which has an enum like the following
enum TestEnum {
FIRST = 0,
SECOND = 100,
THIRD = 200,
FOURTH = 300,
}
It’s not exported, but used in another class type like the following
declare class TestClass {
testEnumProp: TestEnum | string | null;
}
Now I need that enum for my own code, but I can’t directly use it since it’s not directly exported. So I tried something like the following to extract the type
type TestEnumType = Exclude<NonNullable<TestClass['testEnumProp']>,string>
Which worked in the following case
const val:TestEnumType = TestEnum.FIRST;
But since I do not have access to TestEnum
directly, I can’t use TestEnum.FIRST
and have to use my extracted type
const val2:TestEnumType = TestEnumType.FIRST;
But it doesn’t work since TestEnumType
is a type, but not the enum itself. This is the error I receive on my IDE.
'TestEnumType' only refers to a type, but is being used as a value here.ts(2693)
Any idea if I can somehow use TestEnumType.FIRST
using some TS magic?