'How to use same enum in multiple files in Typescript without import

I've been struggling with this now longer than I should and surprisingly, the existing questions (and there are many) don't really help further.

My goal is to declare and define enum on a global level, such that I can use that said enum in any file without having to import them. Now, to my understand you can't do this with a d.ts file. I also saw other work arounds (e.g. this one https://github.com/Microsoft/TypeScript/issues/14975 ) that don't seem best-practice but rather a "fix". Or questions, that aren't fully answered (e.g. Enums in typescript d.ts file )

Now, apparently a way to go is to create a common.ts and handle any enum in that file. How exactly do I have to proceed in order to make this possible:

Some global.ts file

 enum someEnum{
        first = 'someString',
        second = "someOtherString'
    }

a.ts file

//without any imports
const myFirstEnumValue = someEnum.first // resulting in "someString"

Context

I'm writing a React, Electron App and don't want to declare/define my enums twice, in electron.ts (sometimes called main) and in any react file. This works without any issue with types and interfaces in a file called types.d.ts (filepath is added to typeRoots in tsconfig.json) but again, not with enums



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source