In my program, I have lots of files with enum definitions like this and some files which join enums together. The enums are string-enums, so the indexing is not part of the problem. When I join enums together I get the error "Cannot access 'Both' before initialization". There are also circular imports, since I am using the combined enum in the first file. I understand the error message, however I import the files containing the necessary enums before defining 'Both'. Is this a typescript bug or am I missing something? I am using typescript in a React environment, so maybe I am missing the right tsconfig lines.
// firstFile.ts
export enum One
{
A,
B,
}
export enum Two
{
C = 2,
D,
}
// secondFile.ts, throws error
import { One, Two } from './firstFile';
export const Both =
{
...One,
...Two,
}
import { One, Two } from './firstFile';, Problem might be in a way how you import'firstFile', because you are using absolute import instead of relative