TS2669

error TS2669: Augmentations for the global scope can only be directly nested in external modules or ambient module declarations.

Solution

Bad Code ❌

1
2
3
4
5
6
7
declare global {
namespace NodeJS {
interface Global {
__coverage__: {};
}
}
}

You have to turn your code into a module by adding an import or export statement to your code. The easiest way to solve the problem is exporting an empty object:

Fixed Code ✔️

1
2
3
4
5
6
7
8
9
declare global {
namespace NodeJS {
interface Global {
__coverage__: {};
}
}
}

export {}