Augmentations for the global scope can only be directly nested in external modules or ambient module declarations(2669)

后端 未结 2 942
不思量自难忘°
不思量自难忘° 2021-02-04 23:14

I would like to store my NodeJS config in the global scope.

I tried to follow this => Extending TypeScript Global object in node.js and other solution on stackoverflow,

相关标签:
2条回答
  • 2021-02-04 23:35

    You can indicate that the file is a module like so:

    export {};
    
    declare global {
        namespace NodeJS {
            interface Global {
                config: MyConfigType
            }
        }
    }
    
    0 讨论(0)
  • 2021-02-04 23:38

    Or if you're trying to add a global type within the browser context:

    export {};
    
    declare global {
      interface Window {
        ENV: any;
      }
    }
    
    0 讨论(0)
提交回复
热议问题